davebulaval commited on
Commit
285603e
1 Parent(s): 7dfa42a

Upload riscbac.py

Browse files
Files changed (1) hide show
  1. riscbac.py +112 -0
riscbac.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """RISCBAC: a synthetic bilingual automotive insurance contract dataset"""
15
+
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ _CITATION = """\
25
+ @misc{beaucheminrisc,
26
+ title={{RISC: Generating Realistic Synthetic Bilingual Insurance
27
+ Contract}},
28
+ author={David Beauchemin and Richard Khoury},
29
+ year={2023},
30
+ eprint={2304.04212},
31
+ archivePrefix={arXiv}
32
+ }
33
+ """
34
+
35
+ # You can copy an official description
36
+ _DESCRIPTION = """\
37
+ RISCBAC was created using [RISC](https://github.com/GRAAL-Research/risc), an open-source Python package data
38
+ generator. RISC generates look-alike automobile insurance contracts based on the Quebec regulatory insurance
39
+ form in French and English.
40
+
41
+ It contains 10,000 English and French insurance contracts generated using the same seed. Thus, contracts share
42
+ the same deterministic synthetic data (RISCBAC can be used as an aligned dataset). RISC can be used to generate
43
+ more data for RISCBAC.
44
+ """
45
+
46
+ _HOMEPAGE = "https://huggingface.co/datasets/davebulaval/RISCBAC"
47
+
48
+ _LICENSE = "Attribution 4.0 International (CC BY 4.0)"
49
+
50
+ _URLS = {
51
+ "en": "https://huggingface.co/datasets/davebulaval/RISCBAC/blob/main/en.zip",
52
+ "fr": "https://huggingface.co/datasets/davebulaval/RISCBAC/blob/main/fr.zip",
53
+ }
54
+
55
+
56
+ class RISCBAC(datasets.GeneratorBasedBuilder):
57
+ """RISCBAC: a synthetic bilingual automotive insurance contract dataset"""
58
+
59
+ VERSION = datasets.Version("1.1.0")
60
+
61
+ BUILDER_CONFIGS = [
62
+ datasets.BuilderConfig(
63
+ name="en", version=VERSION, description="This part of the dataset are automobile contract in English."
64
+ ),
65
+ datasets.BuilderConfig(
66
+ name="fr", version=VERSION, description="This part of the dataset are automobile contract in French."
67
+ ),
68
+ ]
69
+
70
+ def _info(self):
71
+ features = datasets.Features(
72
+ {
73
+ "text": datasets.Value("string"),
74
+ }
75
+ )
76
+ return datasets.DatasetInfo(
77
+ description=_DESCRIPTION,
78
+ features=features,
79
+ homepage=_HOMEPAGE,
80
+ license=_LICENSE,
81
+ citation=_CITATION,
82
+ )
83
+
84
+ def _split_generators(self, dl_manager):
85
+ urls = _URLS[self.config.name]
86
+ data_dir = dl_manager.download_and_extract(urls)
87
+ if self.config.name == "en":
88
+ return [
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.TRAIN,
91
+ gen_kwargs={
92
+ "files_dir_path": os.path.join(data_dir, "en"),
93
+ "split": "full",
94
+ },
95
+ )
96
+ ]
97
+ else:
98
+ return [
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TRAIN,
101
+ gen_kwargs={
102
+ "files_dir_path": os.path.join(data_dir, "fr"),
103
+ "split": "full",
104
+ },
105
+ ),
106
+ ]
107
+
108
+ def _generate_examples(self, files_dir_path, split):
109
+ files = os.listdir(files_dir_path)
110
+ for key, file in enumerate(files):
111
+ with open(file, "r") as f:
112
+ yield key, {"text": f.readlines()}