|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import csv
|
|
|
import json
|
|
|
import os
|
|
|
from decimal import Decimal
|
|
|
|
|
|
import datasets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_CITATION = ""
|
|
|
|
|
|
|
|
|
_DESCRIPTION = """\
|
|
|
ClueWeb-Reco is a novel zero-shot test set derived from real, \
|
|
|
consented user browsing sequences,
|
|
|
aligning with modern recommendation scenarios while ensuring privacy.
|
|
|
"""
|
|
|
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/cx-cmu/ClueWeb-Reco"
|
|
|
|
|
|
_LICENSE = "mit"
|
|
|
|
|
|
|
|
|
|
|
|
_URLS = {
|
|
|
"input": "https://huggingface.co/datasets/cx-cmu/ClueWeb-Reco/tree/main/interaction_splits",
|
|
|
"target": "https://huggingface.co/datasets/cx-cmu/ClueWeb-Reco/tree/main/interaction_splits",
|
|
|
"mapping": "https://huggingface.co/datasets/cx-cmu/ClueWeb-Reco/tree/main",
|
|
|
}
|
|
|
|
|
|
|
|
|
class ClueWebRecoDataset(datasets.GeneratorBasedBuilder):
|
|
|
"""Process the ClueWeb-Reco zero-shot dataset"""
|
|
|
|
|
|
VERSION = datasets.Version("1.1.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [
|
|
|
datasets.BuilderConfig(name="input", version=VERSION, description="This is the input parts of the dataset"),
|
|
|
datasets.BuilderConfig(name="target", version=VERSION, description="This is the target parts of the dataset"),
|
|
|
datasets.BuilderConfig(name="mapping", version=VERSION, description="This is the mapping between official ClueWeb ids and our internal ClueWeb ids"),
|
|
|
]
|
|
|
|
|
|
DEFAULT_CONFIG_NAME = "input"
|
|
|
|
|
|
def _info(self):
|
|
|
if self.config.name == "input":
|
|
|
features = datasets.Features(
|
|
|
{
|
|
|
"session_id": datasets.Value("string"),
|
|
|
"cw_internal_id": datasets.Value("int32"),
|
|
|
"timestamp": datasets.Value("string")
|
|
|
}
|
|
|
)
|
|
|
elif self.config.name == "target":
|
|
|
features = datasets.Features(
|
|
|
{
|
|
|
"session_id": datasets.Value("string"),
|
|
|
"target_cw_internal_id": datasets.Value("int32"),
|
|
|
"timestamp": datasets.Value("string")
|
|
|
}
|
|
|
)
|
|
|
elif self.config.name == "mapping":
|
|
|
features = datasets.Features(
|
|
|
{
|
|
|
"cwid": datasets.Value("string"),
|
|
|
"cw_internal_id": datasets.Value("int32"),
|
|
|
}
|
|
|
)
|
|
|
return datasets.DatasetInfo(
|
|
|
|
|
|
description=_DESCRIPTION,
|
|
|
|
|
|
features=features,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE,
|
|
|
|
|
|
license=_LICENSE,
|
|
|
|
|
|
citation=_CITATION,
|
|
|
)
|
|
|
|
|
|
def _split_generators(self, dl_manager):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS[self.config.name]
|
|
|
data_dir = dl_manager.download_and_extract(urls)
|
|
|
data_dir = self.config.data_dir
|
|
|
|
|
|
if self.config.name == "input":
|
|
|
return [
|
|
|
datasets.SplitGenerator(
|
|
|
name=datasets.Split.VALIDATION,
|
|
|
gen_kwargs={
|
|
|
"input_path": os.path.join(data_dir, "interaction_splits/valid_inter_input.tsv"),
|
|
|
}
|
|
|
),
|
|
|
datasets.SplitGenerator(
|
|
|
name=datasets.Split.TEST,
|
|
|
gen_kwargs={
|
|
|
"input_path": os.path.join(data_dir, "interaction_splits/test_inter_input.tsv"),
|
|
|
},
|
|
|
),
|
|
|
]
|
|
|
elif self.config.name == "target":
|
|
|
return [
|
|
|
datasets.SplitGenerator(
|
|
|
name=datasets.Split.VALIDATION,
|
|
|
gen_kwargs={
|
|
|
"target_path": os.path.join(data_dir, "interaction_splits/valid_inter_target.tsv"),
|
|
|
},
|
|
|
),
|
|
|
]
|
|
|
|
|
|
elif self.config.name == "mapping":
|
|
|
return [
|
|
|
datasets.SplitGenerator(
|
|
|
name=datasets.Split.TRAIN,
|
|
|
gen_kwargs={
|
|
|
"mapping_path": os.path.join(data_dir, "cwid_to_id.tsv"),
|
|
|
},
|
|
|
),
|
|
|
]
|
|
|
|
|
|
|
|
|
def _generate_examples(self, input_path=None, target_path=None, mapping_path=None):
|
|
|
"""
|
|
|
Generates examples based on the input and (optionally) target files.
|
|
|
If the configuration is `input`, `target`, or `mapping`, this handles each separately.
|
|
|
"""
|
|
|
|
|
|
if self.config.name == "input":
|
|
|
if input_path is None:
|
|
|
raise ValueError("Input configuration requires an input_path.")
|
|
|
|
|
|
|
|
|
with open(input_path, encoding="utf-8") as f:
|
|
|
input_lines = f.readlines()[1:]
|
|
|
for idx, line in enumerate(input_lines):
|
|
|
session_id, cw_internal_id, timestamp = line.strip().split("\t")
|
|
|
yield idx, {
|
|
|
"session_id": session_id.strip(),
|
|
|
"cw_internal_id": int(cw_internal_id.strip()),
|
|
|
"timestamp": str(Decimal(timestamp)),
|
|
|
}
|
|
|
|
|
|
elif self.config.name == "target":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if target_path is None:
|
|
|
raise ValueError("Target configuration requires an target_path.")
|
|
|
|
|
|
with open(target_path, encoding="utf-8") as f:
|
|
|
target_lines = f.readlines()[1:]
|
|
|
for idx, line in enumerate(target_lines):
|
|
|
session_id, target_cw_internal_id, timestamp = line.strip().split("\t")
|
|
|
yield idx, {
|
|
|
"session_id": session_id.strip(),
|
|
|
"target_cw_internal_id": int(target_cw_internal_id.strip()),
|
|
|
"timestamp": str(Decimal(timestamp)),
|
|
|
}
|
|
|
|
|
|
elif self.config.name == "mapping":
|
|
|
|
|
|
if mapping_path is None:
|
|
|
raise ValueError("Mapping configuration requires an mapping_path.")
|
|
|
|
|
|
|
|
|
with open(mapping_path, encoding="utf-8") as f:
|
|
|
for idx, line in enumerate(f):
|
|
|
cwid, cw_internal_id = line.strip().split("\t")
|
|
|
yield idx, {
|
|
|
"cwid": cwid.strip(),
|
|
|
"cw_internal_id": int(cw_internal_id.strip()),
|
|
|
} |