MrLight commited on
Commit
7bfc70b
·
verified ·
1 Parent(s): e3acc18

Create beir-corpus.py

Browse files
Files changed (1) hide show
  1. beir-corpus.py +118 -0
beir-corpus.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the 'License');
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an 'AS IS' BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+
18
+ import json
19
+
20
+ import datasets
21
+
22
+ _CITATION = '''
23
+ @inproceedings{
24
+ thakur2021beir,
25
+ title={{BEIR}: A Heterogeneous Benchmark for Zero-shot Evaluation of Information Retrieval Models},
26
+ author={Nandan Thakur and Nils Reimers and Andreas R{\"u}ckl{\'e} and Abhishek Srivastava and Iryna Gurevych},
27
+ booktitle={Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 2)},
28
+ year={2021},
29
+ url={https://openreview.net/forum?id=wCu6T5xFjeJ}
30
+ }
31
+ '''
32
+
33
+ all_data = [
34
+ 'arguana',
35
+ 'climate-fever',
36
+ 'cqadupstack-android',
37
+ 'cqadupstack-english',
38
+ 'cqadupstack-gaming',
39
+ 'cqadupstack-gis',
40
+ 'cqadupstack-mathematica',
41
+ 'cqadupstack-physics',
42
+ 'cqadupstack-programmers',
43
+ 'cqadupstack-stats',
44
+ 'cqadupstack-tex',
45
+ 'cqadupstack-unix',
46
+ 'cqadupstack-webmasters',
47
+ 'cqadupstack-wordpress',
48
+ 'dbpedia-entity',
49
+ 'fever',
50
+ 'fiqa',
51
+ 'hotpotqa',
52
+ 'nfcorpus',
53
+ 'quora',
54
+ 'scidocs',
55
+ 'scifact',
56
+ 'trec-covid',
57
+ 'webis-touche2020',
58
+ 'nq'
59
+ ]
60
+
61
+ _DESCRIPTION = 'dataset load script for BEIR corpus'
62
+
63
+ _DATASET_URLS = {
64
+ data: {
65
+ 'train': f'https://huggingface.co/datasets/Tevatron/beir-corpus/resolve/main/{data}.jsonl.gz',
66
+ } for data in all_data
67
+ }
68
+
69
+
70
+ class BeirCorpus(datasets.GeneratorBasedBuilder):
71
+ BUILDER_CONFIGS = [
72
+ datasets.BuilderConfig(
73
+ version=datasets.Version('1.1.0'),
74
+ name=data,
75
+ description=f'BEIR dataset corpus {data}.'
76
+ ) for data in all_data
77
+ ]
78
+
79
+ def _info(self):
80
+ features = datasets.Features({
81
+ 'docid': datasets.Value('string'),
82
+ 'title': datasets.Value('string'),
83
+ 'text': datasets.Value('string'),
84
+ })
85
+
86
+ return datasets.DatasetInfo(
87
+ # This is the description that will appear on the datasets page.
88
+ description=_DESCRIPTION,
89
+ # This defines the different columns of the dataset and their types
90
+ features=features, # Here we define them above because they are different between the two configurations
91
+ supervised_keys=None,
92
+ # Homepage of the dataset for documentation
93
+ homepage='https://github.com/beir-cellar/beir',
94
+ # License for the dataset if available
95
+ license='',
96
+ # Citation for the dataset
97
+ citation=_CITATION,
98
+ )
99
+
100
+ def _split_generators(self, dl_manager):
101
+ data = self.config.name
102
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[data])
103
+
104
+ splits = [
105
+ datasets.SplitGenerator(
106
+ name='train',
107
+ gen_kwargs={
108
+ 'filepath': downloaded_files['train'],
109
+ },
110
+ ),
111
+ ]
112
+ return splits
113
+
114
+ def _generate_examples(self, filepath):
115
+ with open(filepath, encoding="utf-8") as f:
116
+ for line in f:
117
+ data = json.loads(line)
118
+ yield data['docid'], data