philipphager/baidu-ultr_uva-mlm-ctr
收藏Baidu ULTR Dataset - UvA BERT-12l-12h
数据集概述
该数据集包含查询-文档向量和点击数据,是Baidu Unbiased Learning to Rank dataset的一个子集。数据集使用了一个具有12层的BERT交叉编码器,该编码器在掩码语言模型(MLM)和点击率(CTR)预测任务上进行了训练,用于计算查询-文档向量(768维)。模型文件位于model/目录下。
数据加载
加载训练/测试点击数据集
Python from datasets import load_dataset
dataset = load_dataset( "philipphager/baidu-ultr_baidu-mlm-ctr", name="clicks", split="train", # ["train", "test"] cache_dir="~/.cache/huggingface", )
dataset.set_format("torch") # [None, "numpy", "torch", "tensorflow", "pandas", "arrow"]
加载专家标注数据集
Python from datasets import load_dataset
dataset = load_dataset( "philipphager/baidu-ultr_baidu-mlm-ctr", name="annotations", split="test", cache_dir="~/.cache/huggingface", )
dataset.set_format("torch") # [None, "numpy", "torch", "tensorflow", "pandas", "arrow"]
可用特征
每个点击/标注数据集的行包含以下属性。可以使用自定义的collate_fn选择特定特征(见下文):
点击数据集
| 名称 | 数据类型 | 描述 |
|---|---|---|
| query_id | string | Baidu查询ID |
| query_md5 | string | 查询文本的MD5哈希 |
| query | List[int32] | 查询令牌列表 |
| query_length | int32 | 查询令牌数量 |
| n | int32 | 当前查询的文档数量,用于填充 |
| url_md5 | List[string] | 文档URL的MD5哈希,最可靠的文档标识符 |
| text_md5 | List[string] | 文档标题和摘要的MD5哈希 |
| title | List[List[int32]] | 文档标题的令牌列表 |
| abstract | List[List[int32]] | 文档摘要的令牌列表 |
| query_document_embedding | Tensor[Tensor[float16]] | BERT CLS令牌 |
| click | Tensor[int32] | 文档点击/未点击 |
| position | Tensor[int32] | 排名中的位置(不一定与原始项目位置匹配) |
| media_type | Tensor[int32] | 文档类型(推荐使用标签编码,因为ID不占据连续的整数范围) |
| displayed_time | Tensor[float32] | 文档在屏幕上显示的秒数 |
| serp_height | Tensor[int32] | 文档在屏幕上的像素高度 |
| slipoff_count_after_click | Tensor[int32] | 点击后文档被滚动出屏幕的次数 |
| bm25 | Tensor[float32] | 文档的BM25分数 |
| bm25_title | Tensor[float32] | 文档标题的BM25分数 |
| bm25_abstract | Tensor[float32] | 文档摘要的BM25分数 |
| tf_idf | Tensor[float32] | 文档的TF-IDF分数 |
| tf | Tensor[float32] | 文档的词频 |
| idf | Tensor[float32] | 文档的逆文档频率 |
| ql_jelinek_mercer_short | Tensor[float32] | 使用Jelinek-Mercer平滑(alpha = 0.1)的文档查询似然分数 |
| ql_jelinek_mercer_long | Tensor[float32] | 使用Jelinek-Mercer平滑(alpha = 0.7)的文档查询似然分数 |
| ql_dirichlet | Tensor[float32] | 使用Dirichlet平滑(lambda = 128)的文档查询似然分数 |
| document_length | Tensor[int32] | 文档长度 |
| title_length | Tensor[int32] | 文档标题长度 |
| abstract_length | Tensor[int32] | 文档摘要长度 |
专家标注数据集
| 名称 | 数据类型 | 描述 |
|---|---|---|
| query_id | string | Baidu查询ID |
| query_md5 | string | 查询文本的MD5哈希 |
| query | List[int32] | 查询令牌列表 |
| query_length | int32 | 查询令牌数量 |
| frequency_bucket | int32 | 查询的月频率(桶),从0(高频率)到9(低频率) |
| n | int32 | 当前查询的文档数量,用于填充 |
| url_md5 | List[string] | 文档URL的MD5哈希,最可靠的文档标识符 |
| text_md5 | List[string] | 文档标题和摘要的MD5哈希 |
| title | List[List[int32]] | 文档标题的令牌列表 |
| abstract | List[List[int32]] | 文档摘要的令牌列表 |
| query_document_embedding | Tensor[Tensor[float16]] | BERT CLS令牌 |
| label | Tensor[int32] | 相关性判断,范围从0(差)到4(优秀) |
| bm25 | Tensor[float32] | 文档的BM25分数 |
| bm25_title | Tensor[float32] | 文档标题的BM25分数 |
| bm25_abstract | Tensor[float32] | 文档摘要的BM25分数 |
| tf_idf | Tensor[float32] | 文档的TF-IDF分数 |
| tf | Tensor[float32] | 文档的词频 |
| idf | Tensor[float32] | 文档的逆文档频率 |
| ql_jelinek_mercer_short | Tensor[float32] | 使用Jelinek-Mercer平滑(alpha = 0.1)的文档查询似然分数 |
| ql_jelinek_mercer_long | Tensor[float32] | 使用Jelinek-Mercer平滑(alpha = 0.7)的文档查询似然分数 |
| ql_dirichlet | Tensor[float32] | 使用Dirichlet平滑(lambda = 128)的文档查询似然分数 |
| document_length | Tensor[int32] | 文档长度 |
| title_length | Tensor[int32] | 文档标题长度 |
| abstract_length | Tensor[int32] | 文档摘要长度 |
示例PyTorch collate函数
每个数据集样本是一个包含多个文档的单个查询。以下示例展示了如何通过应用填充来创建包含多个查询和不同数量文档的批次:
Python import torch from typing import List from collections import defaultdict from torch.nn.utils.rnn import pad_sequence from torch.utils.data import DataLoader
def collate_clicks(samples: List): batch = defaultdict(lambda: [])
for sample in samples:
batch["query_document_embedding"].append(sample["query_document_embedding"])
batch["position"].append(sample["position"])
batch["click"].append(sample["click"])
batch["n"].append(sample["n"])
return {
"query_document_embedding": pad_sequence(
batch["query_document_embedding"], batch_first=True
),
"position": pad_sequence(batch["position"], batch_first=True),
"click": pad_sequence(batch["click"], batch_first=True),
"n": torch.tensor(batch["n"]),
}
loader = DataLoader(dataset, collate_fn=collate_clicks, batch_size=16)



