Datasets:

Languages:
Chinese
ArXiv:
License:
File size: 5,597 Bytes
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389d322
7c310a5
 
e54c647
389d322
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
 
 
 
e54c647
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389d322
 
 
 
e54c647
 
 
 
389d322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e54c647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40212e9
e54c647
 
 
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
185
# 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

_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 = """
@article{sigir2023,
title={T2Ranking},
author={Qian Dong},
volume={2023},
number={2},
pages={99-110},
year={2022}
}
"""

_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"),
        "score": datasets.Value("float32"),
    },
    "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:
            # print('')
            split_data_path = _URLS_DICT[self.config.name]
            # print(split_data_path)
            filepath = dl_manager.download(split_data_path)
            # print(filepath)
            # print('')
            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):
        data = pd.read_csv(filepath, sep='\t', quoting=3)
        keys = _FEATURES_DICT[self.config.name].keys()
        for idx in range(data.shape[0]):
            yield idx, {key: data[key][idx] for key in keys}