|
import os |
|
import json |
|
import datasets |
|
import datetime |
|
|
|
_CITATION = """ |
|
@inproceedings{zellersluhessel2021merlot, |
|
title={MERLOT: Multimodal Neural Script Knowledge Models}, |
|
author={Zellers, Rowan and Lu, Ximing and Hessel, Jack and Yu, Youngjae and Park, Jae Sung and Cao, Jize and Farhadi, Ali and Choi, Yejin}, |
|
booktitle={Advances in Neural Information Processing Systems 34}, |
|
year={2021} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
YT-Temporal-180M, a large and diverse dataset of 6 million videos (spanning 180M extracted frames) |
|
that covers diverse topics. |
|
""" |
|
|
|
_URL_BASE = "https://rowanzellers.com/merlot/#data" |
|
|
|
url_numbers = ["00" + str(i) if i<10 else "0"+ str(i) for i in range(100)] |
|
_DL_URLS = ["https://storage.googleapis.com/merlot/yttemporal180m/yttemporal180m_{num}of100.jsonl.gz" for num in url_numbers] |
|
|
|
def json_serializer(o): |
|
if isinstance(o, datetime): |
|
return str(o) |
|
|
|
raise TypeError( |
|
f"Object of type {o.__class__.__name__} is not JSON serializable") |
|
|
|
class yttemporal180mConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for ActivityNet Captions.""" |
|
|
|
def __init__(self, **kwargs): |
|
super(yttemporal180mConfig, self).__init__( |
|
version=datasets.Version("2.1.0", ""), **kwargs) |
|
|
|
|
|
class yttemporal180m(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG_NAME = "all" |
|
BUILDER_CONFIGS = [ |
|
yttemporal180mConfig( |
|
name="default", description="Default full yttemporal180m dataset"), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"video_id": datasets.Value("string"), |
|
"video_url": datasets.Value("string"), |
|
"asr": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"quality": datasets.Value("int8"), |
|
"meta": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_URL_BASE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
archive_paths = [dl_manager.download_and_extract(url) for url in _DL_URLS] |
|
|
|
train_split = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"jsonl_files": archive_paths |
|
}, |
|
) |
|
] |
|
|
|
return train_split |
|
|
|
def _generate_examples(self, jsonl_files): |
|
"""This function returns the examples.""" |
|
idx = 0 |
|
for file in jsonl_files: |
|
with open(file, encoding="utf-8") as jsonl_file: |
|
json_list = list(jsonl_file) |
|
for json_str in json_list: |
|
infos = json.loads(json_str) |
|
|
|
id = infos['info']['display_id'] |
|
url = "https://www.youtube.com/watch?v=" + id[2:] |
|
asr = "" |
|
for example in infos['denoised']: |
|
asr += example["cleanasr"] |
|
|
|
metadata_dict = { |
|
"asr_info": infos["denoised"], |
|
"info": infos["info"], |
|
"subtitles": infos["subtitles"], |
|
} |
|
yield idx, { |
|
"video_id": id, |
|
"video_url": url, |
|
"asr": asr, |
|
"title": infos['info']['title'], |
|
"quality": infos['info']['quality'], |
|
"meta": json.dumps( |
|
metadata_dict, |
|
default=json_serializer, |
|
indent=2 |
|
) |
|
} |
|
idx += 1 |