piotr-rybak commited on
Commit
34369d3
1 Parent(s): 496f151

upload data

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. data/passages.jsonl +3 -0
  3. data/test.csv +0 -0
  4. legal-questions.py +120 -0
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ data/passages.jsonl filter=lfs diff=lfs merge=lfs -text
data/passages.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c70370268ee068beb2b8f7b3eaab1a696124ed31a68faab7794d8fa399bd99e9
3
+ size 33963958
data/test.csv ADDED
The diff for this file is too large to render. See raw diff
 
legal-questions.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+
16
+ import csv
17
+ import json
18
+
19
+ import datasets
20
+
21
+
22
+ _CITATION = """\
23
+ """
24
+
25
+ _DESCRIPTION = """\
26
+ Legal Questions is a dataset for evaluating passage retrievers.
27
+ """
28
+
29
+ _HOMEPAGE = ""
30
+
31
+ _LICENSE = ""
32
+
33
+ _FEATURES_PAIRS = datasets.Features(
34
+ {
35
+ "question_id": datasets.Value("int32"),
36
+ "question": datasets.Value("string"),
37
+ "passage_id": datasets.Value("string"),
38
+ "answers": datasets.Value("string"),
39
+ "passage_title": datasets.Value("string"),
40
+ "passage_text": datasets.Value("string"),
41
+ "relevant": datasets.Value("bool"),
42
+ }
43
+ )
44
+
45
+ _FEATURES_PASSAGES = datasets.Features(
46
+ {
47
+ "id": datasets.Value("string"),
48
+ "title": datasets.Value("string"),
49
+ "text": datasets.Value("string"),
50
+ }
51
+ )
52
+
53
+ _URLS = {
54
+ "pairs": {
55
+ "test": ["data/test.csv"],
56
+ },
57
+ "passages": {
58
+ "test": ["data/passages.jsonl"],
59
+ },
60
+ }
61
+
62
+
63
+ class LegalQuestions(datasets.GeneratorBasedBuilder):
64
+ """Legal Questions is a dataset for evaluating passage retrievers. """
65
+
66
+ BUILDER_CONFIGS = list(map(lambda x: datasets.BuilderConfig(name=x, version=datasets.Version("1.0.0")), _URLS.keys()))
67
+ DEFAULT_CONFIG_NAME = "pairs"
68
+
69
+ def _info(self):
70
+ if self.config.name == "pairs":
71
+ features = _FEATURES_PAIRS
72
+ else:
73
+ features = _FEATURES_PASSAGES
74
+
75
+ return datasets.DatasetInfo(
76
+ description=_DESCRIPTION,
77
+ features=features,
78
+ homepage=_HOMEPAGE,
79
+ license=_LICENSE,
80
+ citation=_CITATION,
81
+ )
82
+
83
+ def _split_generators(self, dl_manager):
84
+ urls = _URLS[self.config.name]
85
+ data_dir = dl_manager.download_and_extract(urls)
86
+ return [
87
+ datasets.SplitGenerator(
88
+ name=datasets.Split.TEST,
89
+ gen_kwargs={
90
+ "filepaths": data_dir["test"],
91
+ },
92
+ ),
93
+ ]
94
+
95
+ @staticmethod
96
+ def _parse_bool(text):
97
+ if text == 'True':
98
+ return True
99
+ elif text == 'False':
100
+ return False
101
+ else:
102
+ raise ValueError
103
+
104
+ def _generate_examples(self, filepaths):
105
+ if self.config.name == "pairs":
106
+ boolean_features = [name for name, val in _FEATURES_PAIRS.items() if val.dtype == "bool"]
107
+
108
+ for filepath in filepaths:
109
+ with open(filepath, encoding="utf-8") as f:
110
+ data = csv.DictReader(f)
111
+ for i, row in enumerate(data):
112
+ for boolean_feature in boolean_features:
113
+ row[boolean_feature] = self._parse_bool(row[boolean_feature])
114
+ yield i, row
115
+ else:
116
+ for filepath in filepaths:
117
+ with open(filepath, encoding="utf-8") as f:
118
+ for i, row in enumerate(f):
119
+ parsed_row = json.loads(row)
120
+ yield i, parsed_row