Datasets:
ArXiv:
License:
Commit
•
4534c51
1
Parent(s):
a95dc38
Update baidu-ultr_uva-mlm-ctr.py
Browse files- baidu-ultr_uva-mlm-ctr.py +93 -18
baidu-ultr_uva-mlm-ctr.py
CHANGED
@@ -9,20 +9,23 @@ from datasets import Features, Value, Array2D, Sequence, SplitGenerator, Split
|
|
9 |
|
10 |
_CITATION = """\
|
11 |
@InProceedings{huggingface:dataset,
|
12 |
-
title = {philipphager/baidu-
|
13 |
author={Philipp Hager, Romain Deffayet},
|
14 |
year={2023}
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
-
Query-document vectors and clicks for a subset of the
|
20 |
-
|
21 |
|
22 |
-
|
|
|
|
|
|
|
23 |
"""
|
24 |
|
25 |
-
_HOMEPAGE = "https://huggingface.co/datasets/philipphager/baidu-
|
26 |
_LICENSE = "cc-by-nc-4.0"
|
27 |
_VERSION = "0.1.0"
|
28 |
|
@@ -49,30 +52,69 @@ class BaiduUltrBuilder(datasets.GeneratorBasedBuilder):
|
|
49 |
|
50 |
CLICK_FEATURES = Features(
|
51 |
{
|
|
|
52 |
"query_id": Value("string"),
|
53 |
"query_md5": Value("string"),
|
|
|
|
|
|
|
|
|
54 |
"url_md5": Sequence(Value("string")),
|
55 |
"text_md5": Sequence(Value("string")),
|
|
|
|
|
56 |
"query_document_embedding": Array2D((None, 768), "float16"),
|
57 |
"click": Sequence(Value("int32")),
|
58 |
-
|
59 |
"position": Sequence(Value("int32")),
|
60 |
"media_type": Sequence(Value("int32")),
|
61 |
"displayed_time": Sequence(Value("float32")),
|
62 |
"serp_height": Sequence(Value("int32")),
|
63 |
"slipoff_count_after_click": Sequence(Value("int32")),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
)
|
66 |
|
67 |
ANNOTATION_FEATURES = Features(
|
68 |
{
|
|
|
69 |
"query_id": Value("string"),
|
70 |
"query_md5": Value("string"),
|
71 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
"query_document_embedding": Array2D((None, 768), "float16"),
|
73 |
"label": Sequence(Value("int32")),
|
74 |
-
|
75 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
)
|
78 |
|
@@ -104,19 +146,34 @@ class BaiduUltrBuilder(datasets.GeneratorBasedBuilder):
|
|
104 |
query_columns = [
|
105 |
"query_id",
|
106 |
"query_md5",
|
|
|
|
|
107 |
]
|
108 |
|
109 |
agg_columns = [
|
110 |
-
"query_md5",
|
111 |
"url_md5",
|
112 |
"text_md5",
|
113 |
-
"
|
114 |
-
"
|
115 |
"query_document_embedding",
|
|
|
|
|
116 |
"media_type",
|
117 |
"displayed_time",
|
118 |
"serp_height",
|
119 |
"slipoff_count_after_click",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
]
|
121 |
|
122 |
return [
|
@@ -142,12 +199,28 @@ class BaiduUltrBuilder(datasets.GeneratorBasedBuilder):
|
|
142 |
query_columns = [
|
143 |
"query_id",
|
144 |
"query_md5",
|
|
|
|
|
145 |
"frequency_bucket",
|
146 |
]
|
147 |
agg_columns = [
|
148 |
"text_md5",
|
149 |
-
"
|
|
|
150 |
"query_document_embedding",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
]
|
152 |
|
153 |
return [
|
@@ -187,21 +260,23 @@ class BaiduUltrBuilder(datasets.GeneratorBasedBuilder):
|
|
187 |
aggregated per query. E.g., click, position, query_document_embeddings, etc.
|
188 |
:return:
|
189 |
"""
|
|
|
190 |
for file in files:
|
191 |
df = pd.read_feather(file)
|
192 |
-
|
193 |
sample_key = None
|
194 |
sample = None
|
195 |
|
196 |
for i in range(len(df)):
|
197 |
row = df.iloc[i]
|
198 |
|
199 |
-
if
|
200 |
-
if
|
201 |
yield sample_key, sample
|
202 |
|
203 |
-
|
204 |
-
sample_key
|
|
|
205 |
sample = {"n": 0}
|
206 |
|
207 |
for column in query_columns:
|
|
|
9 |
|
10 |
_CITATION = """\
|
11 |
@InProceedings{huggingface:dataset,
|
12 |
+
title = {philipphager/baidu-ultr_uva-mlm-ctr},
|
13 |
author={Philipp Hager, Romain Deffayet},
|
14 |
year={2023}
|
15 |
}
|
16 |
"""
|
17 |
|
18 |
_DESCRIPTION = """\
|
19 |
+
Query-document vectors and clicks for a subset of the Baidu Unbiased Learning to Rank
|
20 |
+
dataset: https://arxiv.org/abs/2207.03051
|
21 |
|
22 |
+
This dataset uses a Jax-based BERT cross-encoder with 12 layers pre-trained for 2 million steps
|
23 |
+
on the Baidu ULTR dataset to create query-document embeddings (768 dims).
|
24 |
+
|
25 |
+
We link the model checkpoint also under `model/`.
|
26 |
"""
|
27 |
|
28 |
+
_HOMEPAGE = "https://huggingface.co/datasets/philipphager/baidu-ultr_baidu-mlm-ctr/"
|
29 |
_LICENSE = "cc-by-nc-4.0"
|
30 |
_VERSION = "0.1.0"
|
31 |
|
|
|
52 |
|
53 |
CLICK_FEATURES = Features(
|
54 |
{
|
55 |
+
### Query features
|
56 |
"query_id": Value("string"),
|
57 |
"query_md5": Value("string"),
|
58 |
+
"query": Sequence(Value("int32")),
|
59 |
+
"query_length": Value("int32"),
|
60 |
+
"n": Value("int32"),
|
61 |
+
### Doc features
|
62 |
"url_md5": Sequence(Value("string")),
|
63 |
"text_md5": Sequence(Value("string")),
|
64 |
+
"title": Sequence(Sequence(Value("int32"))),
|
65 |
+
"abstract": Sequence(Sequence(Value("int32"))),
|
66 |
"query_document_embedding": Array2D((None, 768), "float16"),
|
67 |
"click": Sequence(Value("int32")),
|
68 |
+
### SERP features
|
69 |
"position": Sequence(Value("int32")),
|
70 |
"media_type": Sequence(Value("int32")),
|
71 |
"displayed_time": Sequence(Value("float32")),
|
72 |
"serp_height": Sequence(Value("int32")),
|
73 |
"slipoff_count_after_click": Sequence(Value("int32")),
|
74 |
+
### LTR features
|
75 |
+
"bm25": Sequence(Value("float32")),
|
76 |
+
"bm25_title": Sequence(Value("float32")),
|
77 |
+
"bm25_abstract": Sequence(Value("float32")),
|
78 |
+
"tf_idf": Sequence(Value("float32")),
|
79 |
+
"tf": Sequence(Value("float32")),
|
80 |
+
"idf": Sequence(Value("float32")),
|
81 |
+
"ql_jelinek_mercer_short": Sequence(Value("float32")),
|
82 |
+
"ql_jelinek_mercer_long": Sequence(Value("float32")),
|
83 |
+
"ql_dirichlet": Sequence(Value("float32")),
|
84 |
+
"document_length": Sequence(Value("int32")),
|
85 |
+
"title_length": Sequence(Value("int32")),
|
86 |
+
"abstract_length": Sequence(Value("int32")),
|
87 |
}
|
88 |
)
|
89 |
|
90 |
ANNOTATION_FEATURES = Features(
|
91 |
{
|
92 |
+
### Query features
|
93 |
"query_id": Value("string"),
|
94 |
"query_md5": Value("string"),
|
95 |
+
"query": Sequence(Value("int32")),
|
96 |
+
"query_length": Value("int32"),
|
97 |
+
"frequency_bucket": Value("int32"),
|
98 |
+
"n": Value("int32"),
|
99 |
+
### Doc features
|
100 |
+
"text_md5": Sequence(Value("string")),
|
101 |
+
"title": Sequence(Sequence(Value("int32"))),
|
102 |
+
"abstract": Sequence(Sequence(Value("int32"))),
|
103 |
"query_document_embedding": Array2D((None, 768), "float16"),
|
104 |
"label": Sequence(Value("int32")),
|
105 |
+
### LTR features
|
106 |
+
"bm25": Sequence(Value("float32")),
|
107 |
+
"bm25_title": Sequence(Value("float32")),
|
108 |
+
"bm25_abstract": Sequence(Value("float32")),
|
109 |
+
"tf_idf": Sequence(Value("float32")),
|
110 |
+
"tf": Sequence(Value("float32")),
|
111 |
+
"idf": Sequence(Value("float32")),
|
112 |
+
"ql_jelinek_mercer_short": Sequence(Value("float32")),
|
113 |
+
"ql_jelinek_mercer_long": Sequence(Value("float32")),
|
114 |
+
"ql_dirichlet": Sequence(Value("float32")),
|
115 |
+
"document_length": Sequence(Value("int32")),
|
116 |
+
"title_length": Sequence(Value("int32")),
|
117 |
+
"abstract_length": Sequence(Value("int32")),
|
118 |
}
|
119 |
)
|
120 |
|
|
|
146 |
query_columns = [
|
147 |
"query_id",
|
148 |
"query_md5",
|
149 |
+
"query",
|
150 |
+
"query_length",
|
151 |
]
|
152 |
|
153 |
agg_columns = [
|
|
|
154 |
"url_md5",
|
155 |
"text_md5",
|
156 |
+
"title",
|
157 |
+
"abstract",
|
158 |
"query_document_embedding",
|
159 |
+
"click",
|
160 |
+
"position",
|
161 |
"media_type",
|
162 |
"displayed_time",
|
163 |
"serp_height",
|
164 |
"slipoff_count_after_click",
|
165 |
+
"bm25",
|
166 |
+
"bm25_title",
|
167 |
+
"bm25_abstract",
|
168 |
+
"tf_idf",
|
169 |
+
"tf",
|
170 |
+
"idf",
|
171 |
+
"ql_jelinek_mercer_short",
|
172 |
+
"ql_jelinek_mercer_long",
|
173 |
+
"ql_dirichlet",
|
174 |
+
"document_length",
|
175 |
+
"title_length",
|
176 |
+
"abstract_length",
|
177 |
]
|
178 |
|
179 |
return [
|
|
|
199 |
query_columns = [
|
200 |
"query_id",
|
201 |
"query_md5",
|
202 |
+
"query",
|
203 |
+
"query_length",
|
204 |
"frequency_bucket",
|
205 |
]
|
206 |
agg_columns = [
|
207 |
"text_md5",
|
208 |
+
"title",
|
209 |
+
"abstract",
|
210 |
"query_document_embedding",
|
211 |
+
"label",
|
212 |
+
"bm25",
|
213 |
+
"bm25_title",
|
214 |
+
"bm25_abstract",
|
215 |
+
"tf_idf",
|
216 |
+
"tf",
|
217 |
+
"idf",
|
218 |
+
"ql_jelinek_mercer_short",
|
219 |
+
"ql_jelinek_mercer_long",
|
220 |
+
"ql_dirichlet",
|
221 |
+
"document_length",
|
222 |
+
"title_length",
|
223 |
+
"abstract_length",
|
224 |
]
|
225 |
|
226 |
return [
|
|
|
260 |
aggregated per query. E.g., click, position, query_document_embeddings, etc.
|
261 |
:return:
|
262 |
"""
|
263 |
+
|
264 |
for file in files:
|
265 |
df = pd.read_feather(file)
|
266 |
+
current_query = None
|
267 |
sample_key = None
|
268 |
sample = None
|
269 |
|
270 |
for i in range(len(df)):
|
271 |
row = df.iloc[i]
|
272 |
|
273 |
+
if current_query != row["query_no"]:
|
274 |
+
if current_query is not None:
|
275 |
yield sample_key, sample
|
276 |
|
277 |
+
current_query = row["query_no"]
|
278 |
+
# Use the query number in sample_key as query_ids are not unique.
|
279 |
+
sample_key = f"{file}-{current_query}"
|
280 |
sample = {"n": 0}
|
281 |
|
282 |
for column in query_columns:
|