antoinelouis commited on
Commit
87ad2a0
1 Parent(s): 3c47619

Delete bsard.py

Browse files
Files changed (1) hide show
  1. bsard.py +0 -169
bsard.py DELETED
@@ -1,169 +0,0 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """BSARD: A Statutory Article Retrieval Dataset in French"""
15
-
16
- import csv
17
- import json
18
- import datasets
19
-
20
-
21
- _CITATION = """\
22
- @inproceedings{louis-spanakis-2022-statutory,
23
- title = "A Statutory Article Retrieval Dataset in {F}rench",
24
- author = "Louis, Antoine and Spanakis, Gerasimos",
25
- booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
26
- month = may,
27
- year = "2022",
28
- address = "Dublin, Ireland",
29
- publisher = "Association for Computational Linguistics",
30
- url = "https://aclanthology.org/2022.acl-long.468",
31
- doi = "10.18653/v1/2022.acl-long.468",
32
- pages = "6789--6803",
33
- }
34
- """
35
- _DESCRIPTION = """\
36
- The Belgian Statutory Article Retrieval Dataset (BSARD) is a French native dataset for studying legal information retrieval.
37
- BSARD consists of more than 22,600 statutory articles from Belgian law and about 1,100 legal questions posed by Belgian citizens
38
- and labeled by experienced jurists with relevant articles from the corpus.
39
- """
40
- _HOMEPAGE = "https://github.com/maastrichtlawtech/bsard"
41
- _LICENSE = "CC BY-NC-SA 4.0"
42
- _URLS = {
43
- "corpus": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/articles.csv",
44
- "test-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_test.csv",
45
- "train-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_train.csv",
46
- "synthetic-questions": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/questions_synthetic.csv",
47
- "train-negatives": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/negatives/bm25_negatives_train.json",
48
- "synthetic-negatives": "https://huggingface.co/datasets/maastrichtlawtech/bsard/resolve/main/negatives/bm25_negatives_synthetic.json",
49
- }
50
-
51
-
52
- class BSARD(datasets.GeneratorBasedBuilder):
53
- """BSARD: A Statutory Article Retrieval Dataset in French"""
54
-
55
- VERSION = datasets.Version("1.0.0")
56
- BUILDER_CONFIGS = [
57
- datasets.BuilderConfig(name="corpus", version=VERSION, description="Knowledge corpus of statutory articles"),
58
- datasets.BuilderConfig(name="questions", version=VERSION, description="Questions labeled with relevant articles"),
59
- datasets.BuilderConfig(name="negatives", version=VERSION, description="Questions labeled with (hard to tell) irrelevant articles"),
60
- ]
61
- DEFAULT_CONFIG_NAME = "questions"
62
-
63
- def _info(self):
64
- if self.config.name == "corpus":
65
- features = {
66
- "id": datasets.Value("int32"),
67
- "article": datasets.Value("string"),
68
- "reference": datasets.Value("string"),
69
- "law_type": datasets.Value("string"),
70
- "description": datasets.Value("string"),
71
- "code": datasets.Value("string"),
72
- "book": datasets.Value("string"),
73
- "part": datasets.Value("string"),
74
- "act": datasets.Value("string"),
75
- "chapter": datasets.Value("string"),
76
- "section": datasets.Value("string"),
77
- "subsection": datasets.Value("string"),
78
- }
79
- elif self.config.name == "questions":
80
- features = {
81
- "id": datasets.Value("int32"),
82
- "question": datasets.Value("string"),
83
- "article_ids": datasets.Sequence(datasets.Value("int32")),
84
- "category": datasets.Value("string"),
85
- "subcategory": datasets.Value("string"),
86
- "extra_description": datasets.Value("string"),
87
- }
88
- elif self.config.name == "negatives":
89
- features = {
90
- "question_id": datasets.Value("int32"),
91
- "article_ids": datasets.Sequence(datasets.Value("int32")),
92
- }
93
- else:
94
- raise ValueError(f"Unknown config name {self.config.name}")
95
- return datasets.DatasetInfo(
96
- description=_DESCRIPTION,
97
- features=datasets.Features(features),
98
- supervised_keys=None,
99
- homepage=_HOMEPAGE,
100
- license=_LICENSE,
101
- citation=_CITATION,
102
- )
103
-
104
- def _split_generators(self, dl_manager):
105
- if self.config.name == "corpus":
106
- dl_path = dl_manager.download_and_extract(_URLS["corpus"])
107
- return [datasets.SplitGenerator(name="corpus", gen_kwargs={"filepath": dl_path})]
108
- elif self.config.name == "questions":
109
- splits = ["train-questions", "test-questions", "synthetic-questions"]
110
- dl_paths = dl_manager.download_and_extract({split: _URLS[split] for split in splits})
111
- return [
112
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": dl_paths["train-questions"], "split": "train"}),
113
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": dl_paths["test-questions"], "split": "test"}),
114
- datasets.SplitGenerator(name="synthetic", gen_kwargs={"filepath": dl_paths["synthetic-questions"], "split": "synthetic"}),
115
- ]
116
- elif self.config.name == "negatives":
117
- splits = ["train-negatives", "synthetic-negatives"]
118
- dl_paths = dl_manager.download_and_extract({split: _URLS[split] for split in splits})
119
- return [
120
- datasets.SplitGenerator(name="train", gen_kwargs={"filepath": dl_paths["train-negatives"], "split": "train"}),
121
- datasets.SplitGenerator(name="synthetic", gen_kwargs={"filepath": dl_paths["synthetic-negatives"], "split": "synthetic"}),
122
- ]
123
- else:
124
- raise ValueError(f"Unknown config name {self.config.name}")
125
-
126
-
127
- def _generate_examples(self, filepath, split=None):
128
- if self.config.name in ["corpus", "questions"]:
129
- with open(filepath, encoding="utf-8") as f:
130
- data = csv.DictReader(f)
131
- for key, row in enumerate(data):
132
- if self.config.name == "corpus":
133
- features = {
134
- "id": int(row["id"]),
135
- "article": row["article"],
136
- "reference": row["reference"],
137
- "law_type": row["law_type"],
138
- "description": row["description"],
139
- "code": row["code"],
140
- "book": row["book"],
141
- "part": row["part"],
142
- "act": row["act"],
143
- "chapter": row["chapter"],
144
- "section": row["section"],
145
- "subsection": row["subsection"],
146
- }
147
- elif self.config.name == "questions":
148
- features = {
149
- "id": int(row["id"]),
150
- "question": row["question"],
151
- "article_ids": [int(num) for num in row["article_ids"].split(",")],
152
- "category": "" if split == "synthetic" else row["category"],
153
- "subcategory": "" if split == "synthetic" else row["subcategory"],
154
- "extra_description": "" if split == "synthetic" else row["extra_description"],
155
- }
156
- else:
157
- raise ValueError(f"Unknown config name {self.config.name}")
158
- yield key, features
159
- elif self.config.name == "negatives":
160
- with open(filepath, encoding="utf-8") as f:
161
- data = json.load(f)
162
- for key, (qid, article_ids) in enumerate(data.items()):
163
- features = {
164
- "question_id": int(qid),
165
- "article_ids": article_ids,
166
- }
167
- yield key, features
168
- else:
169
- raise ValueError(f"Unknown config name {self.config.name}")