Datasets:
Kosuke-Yamada
commited on
Commit
•
5e125ce
1
Parent(s):
6437a78
Delete loading script
Browse files
camera.py
DELETED
@@ -1,147 +0,0 @@
|
|
1 |
-
import ast
|
2 |
-
|
3 |
-
import datasets as ds
|
4 |
-
import pandas as pd
|
5 |
-
|
6 |
-
_DESCRIPTION = """\
|
7 |
-
CAMERA (CyberAgent Multimodal Evaluation for Ad Text GeneRAtion) is the Japanese ad text generation dataset.
|
8 |
-
"""
|
9 |
-
|
10 |
-
_CITATION = """\
|
11 |
-
@misc{mita2024striking,
|
12 |
-
title={Striking Gold in Advertising: Standardization and Exploration of Ad Text Generation},
|
13 |
-
author={Masato Mita and Soichiro Murakami and Akihiko Kato and Peinan Zhang},
|
14 |
-
year={2024},
|
15 |
-
eprint={2309.12030},
|
16 |
-
archivePrefix={arXiv},
|
17 |
-
primaryClass={id='cs.CL' full_name='Computation and Language' is_active=True alt_name='cmp-lg' in_archive='cs' is_general=False description='Covers natural language processing. Roughly includes material in ACM Subject Class I.2.7. Note that work on artificial languages (programming languages, logics, formal systems) that does not explicitly address natural-language issues broadly construed (natural-language processing, computational linguistics, speech, text retrieval, etc.) is not appropriate for this area.'}
|
18 |
-
}
|
19 |
-
"""
|
20 |
-
|
21 |
-
_HOMEPAGE = "https://github.com/CyberAgentAILab/camera"
|
22 |
-
|
23 |
-
_LICENSE = """\
|
24 |
-
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
|
25 |
-
"""
|
26 |
-
|
27 |
-
_URLS = {
|
28 |
-
"without-lp-images": "https://storage.googleapis.com/camera-public/camera-v2.2-minimal.tar.gz",
|
29 |
-
"with-lp-images": "https://storage.googleapis.com/camera-public/camera-v2.2.tar.gz",
|
30 |
-
}
|
31 |
-
|
32 |
-
_DESCRIPTION = {
|
33 |
-
"without-lp-images": "The CAMERA dataset w/o LP images (ver.2.2.0)",
|
34 |
-
"with-lp-images": "The CAMERA dataset w/ LP images (ver.2.2.0)",
|
35 |
-
}
|
36 |
-
|
37 |
-
_VERSION = ds.Version("2.2.0", "")
|
38 |
-
|
39 |
-
|
40 |
-
class CameraConfig(ds.BuilderConfig):
|
41 |
-
def __init__(self, name: str, version: ds.Version = _VERSION, **kwargs):
|
42 |
-
super().__init__(
|
43 |
-
name=name,
|
44 |
-
description=_DESCRIPTION[name],
|
45 |
-
version=version,
|
46 |
-
**kwargs,
|
47 |
-
)
|
48 |
-
|
49 |
-
|
50 |
-
class CameraDataset(ds.GeneratorBasedBuilder):
|
51 |
-
BUILDER_CONFIGS = [CameraConfig(name="without-lp-images")]
|
52 |
-
|
53 |
-
DEFAULT_CONFIG_NAME = "without-lp-images"
|
54 |
-
|
55 |
-
def _info(self) -> ds.DatasetInfo:
|
56 |
-
features = ds.Features(
|
57 |
-
{
|
58 |
-
"asset_id": ds.Value("int64"),
|
59 |
-
"kw": ds.Value("string"),
|
60 |
-
"lp_meta_description": ds.Value("string"),
|
61 |
-
"title_org": ds.Value("string"),
|
62 |
-
"title_ne1": ds.Value("string"),
|
63 |
-
"title_ne2": ds.Value("string"),
|
64 |
-
"title_ne3": ds.Value("string"),
|
65 |
-
"domain": ds.Value("string"),
|
66 |
-
"parsed_full_text_annotation": ds.Sequence(
|
67 |
-
{
|
68 |
-
"text": ds.Value("string"),
|
69 |
-
"xmax": ds.Value("int64"),
|
70 |
-
"xmin": ds.Value("int64"),
|
71 |
-
"ymax": ds.Value("int64"),
|
72 |
-
"ymin": ds.Value("int64"),
|
73 |
-
}
|
74 |
-
),
|
75 |
-
}
|
76 |
-
)
|
77 |
-
|
78 |
-
if self.config.name == "with-lp-images":
|
79 |
-
features["lp_image"] = ds.Image()
|
80 |
-
|
81 |
-
return ds.DatasetInfo(
|
82 |
-
description=_DESCRIPTION,
|
83 |
-
citation=_CITATION,
|
84 |
-
homepage=_HOMEPAGE,
|
85 |
-
license=_LICENSE,
|
86 |
-
features=features,
|
87 |
-
)
|
88 |
-
|
89 |
-
def _split_generators(self, dl_manager: ds.DownloadManager):
|
90 |
-
base_dir = dl_manager.download_and_extract(_URLS[self.config.name])
|
91 |
-
lp_image_dir: str | None = None
|
92 |
-
|
93 |
-
if self.config.name == "without-lp-images":
|
94 |
-
data_dir = f"{base_dir}/camera-v2.2-minimal"
|
95 |
-
elif self.config.name == "with-lp-images":
|
96 |
-
data_dir = f"{base_dir}/camera-v2.2"
|
97 |
-
lp_image_dir = f"{data_dir}/lp-screenshot"
|
98 |
-
else:
|
99 |
-
raise ValueError(f"Invalid config name: {self.config.name}")
|
100 |
-
|
101 |
-
return [
|
102 |
-
ds.SplitGenerator(
|
103 |
-
name=ds.Split.TRAIN,
|
104 |
-
gen_kwargs={
|
105 |
-
"file": f"{data_dir}/train.csv",
|
106 |
-
"lp_image_dir": lp_image_dir,
|
107 |
-
},
|
108 |
-
),
|
109 |
-
ds.SplitGenerator(
|
110 |
-
name=ds.Split.VALIDATION,
|
111 |
-
gen_kwargs={
|
112 |
-
"file": f"{data_dir}/dev.csv",
|
113 |
-
"lp_image_dir": lp_image_dir,
|
114 |
-
},
|
115 |
-
),
|
116 |
-
ds.SplitGenerator(
|
117 |
-
name=ds.Split.TEST,
|
118 |
-
gen_kwargs={
|
119 |
-
"file": f"{data_dir}/test.csv",
|
120 |
-
"lp_image_dir": lp_image_dir,
|
121 |
-
},
|
122 |
-
),
|
123 |
-
]
|
124 |
-
|
125 |
-
def _generate_examples(self, file: str, lp_image_dir: str | None = None):
|
126 |
-
df = pd.read_csv(file)
|
127 |
-
for i, data_dict in enumerate(df.to_dict("records")):
|
128 |
-
asset_id = data_dict["asset_id"]
|
129 |
-
example_dict = {
|
130 |
-
"asset_id": asset_id,
|
131 |
-
"kw": data_dict["kw"],
|
132 |
-
"lp_meta_description": data_dict["lp_meta_description"],
|
133 |
-
"title_org": data_dict["title_org"],
|
134 |
-
"title_ne1": data_dict.get("title_ne1", ""),
|
135 |
-
"title_ne2": data_dict.get("title_ne2", ""),
|
136 |
-
"title_ne3": data_dict.get("title_ne3", ""),
|
137 |
-
"domain": data_dict.get("domain", ""),
|
138 |
-
"parsed_full_text_annotation": ast.literal_eval(
|
139 |
-
data_dict["parsed_full_text_annotation"]
|
140 |
-
),
|
141 |
-
}
|
142 |
-
|
143 |
-
if self.config.name == "with-lp-images" and lp_image_dir is not None:
|
144 |
-
file_name = f"screen-1200-{asset_id}.png"
|
145 |
-
example_dict["lp_image"] = f"{lp_image_dir}/{file_name}"
|
146 |
-
|
147 |
-
yield i, example_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|