Xueguang Ma commited on
Commit
50ad363
·
1 Parent(s): 04d179a

add script

Browse files
Files changed (1) hide show
  1. beir-corpus.py +117 -0
beir-corpus.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ]
59
+
60
+ _DESCRIPTION = 'dataset load script for BEIR corpus'
61
+
62
+ _DATASET_URLS = {
63
+ data: {
64
+ 'test': f'https://huggingface.co/datasets/Tevatron/beir-corpus/resolve/main/{data}.jsonl.gz',
65
+ } for data in all_data
66
+ }
67
+
68
+
69
+ class BeirCorpus(datasets.GeneratorBasedBuilder):
70
+ BUILDER_CONFIGS = [
71
+ datasets.BuilderConfig(
72
+ version=datasets.Version('1.1.0'),
73
+ name=data,
74
+ description=f'BEIR dataset corpus {data}.'
75
+ ) for data in all_data
76
+ ]
77
+
78
+ def _info(self):
79
+ features = datasets.Features({
80
+ 'docid': datasets.Value('string'),
81
+ 'title': datasets.Value('string'),
82
+ 'text': datasets.Value('string'),
83
+ })
84
+
85
+ return datasets.DatasetInfo(
86
+ # This is the description that will appear on the datasets page.
87
+ description=_DESCRIPTION,
88
+ # This defines the different columns of the dataset and their types
89
+ features=features, # Here we define them above because they are different between the two configurations
90
+ supervised_keys=None,
91
+ # Homepage of the dataset for documentation
92
+ homepage='https://github.com/beir-cellar/beir',
93
+ # License for the dataset if available
94
+ license='',
95
+ # Citation for the dataset
96
+ citation=_CITATION,
97
+ )
98
+
99
+ def _split_generators(self, dl_manager):
100
+ data = self.config.name
101
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[data])
102
+
103
+ splits = [
104
+ datasets.SplitGenerator(
105
+ name='train',
106
+ gen_kwargs={
107
+ 'filepath': downloaded_files['train'],
108
+ },
109
+ ),
110
+ ]
111
+ return splits
112
+
113
+ def _generate_examples(self, filepath):
114
+ with open(filepath, encoding="utf-8") as f:
115
+ for line in f:
116
+ data = json.loads(line)
117
+ yield data['docid'], data