Datasets:

Languages:
Chinese
ArXiv:
License:
File size: 5,805 Bytes
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f861f8d
e54c647
 
 
 
 
 
a4a7445
 
 
 
 
 
 
e54c647
 
 
 
 
 
389d322
7c310a5
 
e54c647
389d322
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
 
 
 
e54c647
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
1d17d65
389d322
 
 
 
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389d322
 
 
 
e54c647
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5b2a26
e54c647
f861f8d
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# TODO: Address all TODOs and remove all explanatory comments

import datasets
import json
from typing import List
import pandas as pd
import csv

_LICENSE = "http://www.apache.org/licenses/LICENSE-2.0"
_HOMEPAGE='https://huggingface.co/datasets/THUIR/T2Ranking'

_DESCRIPTION = 'T2Ranking: A large-scale Chinese benchmark for passage retrieval.'
_CITATION = """
@misc{xie2023t2ranking,
      title={T2Ranking: A large-scale Chinese Benchmark for Passage Ranking}, 
      author={Xiaohui Xie and Qian Dong and Bingning Wang and Feiyang Lv and Ting Yao and Weinan Gan and Zhijing Wu and Xiangsheng Li and Haitao Li and Yiqun Liu and Jin Ma},
      year={2023},
      eprint={2304.03679},
      archivePrefix={arXiv},
      primaryClass={cs.IR}
}
"""

_URLS_DICT = {
    "collection": "data/collection.tsv",
    "qrels.train": "data/qrels.train.tsv",
    "qrels.dev": "data/qrels.dev.tsv",
    "qrels.retrieval.train": "data/qrels.retrieval.train.tsv",
    "qrels.retrieval.dev": "data/qrels.retrieval.dev.tsv",
    "queries.train": "data/queries.train.tsv",
    "queries.test": "data/queries.test.tsv",
    "queries.dev": "data/queries.dev.tsv",
    "train.bm25.tsv": "data/train.bm25.tsv",
    "train.mined.tsv": "data/train.mined.tsv",
}

_FEATURES_DICT = {
    'collection': {
        "pid": datasets.Value("int64"),
        "text": datasets.Value("string"),
    },
    'qrels.train': {
        "qid": datasets.Value("int64"),
        "-": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
        "rel": datasets.Value("int64"),
    },
    'qrels.retrieval.train': {
        "qid": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
    },
    'qrels.dev': {
        "qid": datasets.Value("int64"),
        "-": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
        "rel": datasets.Value("int64"),
    },
    'qrels.retrieval.dev': {
        "qid": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
    },
    'queries.train': {
        "qid": datasets.Value("int64"),
        "text": datasets.Value("string"),
    },
    'queries.dev': {
        "qid": datasets.Value("int64"),
        "text": datasets.Value("string"),
    },
    'queries.test': {
        "qid": datasets.Value("int64"),
        "text": datasets.Value("string"),
    },
    "train.bm25.tsv": {
        "qid": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
        "index": datasets.Value("int64"),
    },
    "train.mined.tsv": {
        "qid": datasets.Value("int64"),
        "pid": datasets.Value("int64"),
        "index": datasets.Value("int64"),
        "score": datasets.Value("float32"),
    },
}

class T2RankingConfig(datasets.BuilderConfig):
    """BuilderConfig for T2Ranking."""

    def __init__(self, splits, **kwargs):
        super().__init__(version=datasets.Version("1.0.0"), **kwargs)
        self.splits = splits


class T2Ranking(datasets.GeneratorBasedBuilder):
    """The T2Ranking benchmark."""

    BUILDER_CONFIGS = [
        T2RankingConfig(
            name="collection",
            splits=['train'],
        ),
        T2RankingConfig(
            name="qrels.train",
            splits=['train'],
        ),
        T2RankingConfig(
            name="qrels.dev",
            splits=['train'],
        ),
        T2RankingConfig(
            name="queries.train",
            splits=['train'],
        ),
        T2RankingConfig(
            name="queries.dev",
            splits=['train'],
        ),       
        T2RankingConfig(
            name="queries.test",
            splits=['train'],
        ),
        T2RankingConfig(
            name="qrels.retrieval.train",
            splits=['train'],
        ),
        T2RankingConfig(
            name="qrels.retrieval.dev",
            splits=['train'],
        ),
        T2RankingConfig(
            name="train.bm25.tsv",
            splits=['train'],
        ),
        T2RankingConfig(
            name="train.mined.tsv",
            splits=['train'],
        ),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(_FEATURES_DICT[self.config.name]),
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        split_things = []
        for split_name in self.config.splits:
            split_data_path = _URLS_DICT[self.config.name]
            filepath = dl_manager.download(split_data_path)
            split_thing = datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": filepath,
                }
            )
            split_things.append(split_thing)
        return split_things

    def _generate_examples(self, filepath):
        reader = csv.DictReader(open(filepath), delimiter='\t', quoting=csv.QUOTE_NONE)
        keys = _FEATURES_DICT[self.config.name].keys()
        idx = -1
        for data in reader:
            idx+=1
            yield idx, {key: data[key] for key in keys}