Delete _charttotext-s.py
Browse files- _charttotext-s.py +0 -117
_charttotext-s.py
DELETED
@@ -1,117 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
|
3 |
-
"""
|
4 |
-
The script used to load the dataset from the original source.
|
5 |
-
"""
|
6 |
-
|
7 |
-
import json
|
8 |
-
import datasets
|
9 |
-
import os
|
10 |
-
import csv
|
11 |
-
|
12 |
-
_CITATION = """\
|
13 |
-
@inproceedings{kantharaj2022chart,
|
14 |
-
title={Chart-to-Text: A Large-Scale Benchmark for Chart Summarization},
|
15 |
-
author={Kantharaj, Shankar and Leong, Rixie Tiffany and Lin, Xiang and Masry, Ahmed and Thakkar, Megh and Hoque, Enamul and Joty, Shafiq},
|
16 |
-
booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
|
17 |
-
pages={4005--4023},
|
18 |
-
year={2022}
|
19 |
-
}
|
20 |
-
"""
|
21 |
-
_DESCRIPTION = """\
|
22 |
-
Chart-to-Text is a large-scale benchmark with two datasets and a total of 44,096 charts covering a wide range of topics and chart types.
|
23 |
-
This dataset CONTAINS ONLY the Statista subset from the benchmark.
|
24 |
-
Statista (statista.com) is an online platform that regularly publishes charts on a wide range of topics including economics, market and opinion research.
|
25 |
-
|
26 |
-
Statistics:
|
27 |
-
Total charts: 27868
|
28 |
-
|
29 |
-
=== Chart Type Information ===
|
30 |
-
Number of charts of each chart type
|
31 |
-
column: 16319
|
32 |
-
bar: 8272
|
33 |
-
line: 2646
|
34 |
-
pie: 408
|
35 |
-
table: 223
|
36 |
-
|
37 |
-
=== Token Information ===
|
38 |
-
Average token count per summary: 53.65027989091431
|
39 |
-
Total tokens: 1495126
|
40 |
-
Total types (unique tokens): 39598
|
41 |
-
=== Sentence Information ===
|
42 |
-
Average sentence count per summary: 2.5596741782689825
|
43 |
-
"""
|
44 |
-
|
45 |
-
_URL = "https://github.com/vis-nlp/Chart-to-text/tree/main/statista_dataset/dataset"
|
46 |
-
_LICENSE = "GNU General Public License v3.0"
|
47 |
-
|
48 |
-
class ChartToTextS(datasets.GeneratorBasedBuilder):
|
49 |
-
VERSION = "1.0.0"
|
50 |
-
|
51 |
-
def _info(self):
|
52 |
-
return datasets.DatasetInfo(
|
53 |
-
description=_DESCRIPTION,
|
54 |
-
features=datasets.Features({
|
55 |
-
'title' : datasets.Value(dtype='string'),
|
56 |
-
'ref' : datasets.Value(dtype='string'),
|
57 |
-
'content' : datasets.Value(dtype='large_string'),
|
58 |
-
}),
|
59 |
-
supervised_keys=None,
|
60 |
-
homepage=_URL,
|
61 |
-
citation=_CITATION,
|
62 |
-
license=_LICENSE,
|
63 |
-
)
|
64 |
-
|
65 |
-
def _split_generators(self, dl_manager):
|
66 |
-
"""Returns SplitGenerators."""
|
67 |
-
return [
|
68 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": "dataset", "split" : "train"}),
|
69 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": "dataset", "split" : "dev"}),
|
70 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": "dataset", "split" : "test"}),
|
71 |
-
]
|
72 |
-
|
73 |
-
def _generate_examples(self, filepath, split):
|
74 |
-
data = []
|
75 |
-
mapping_file = split if split != "dev" else "val"
|
76 |
-
|
77 |
-
with open(
|
78 |
-
os.path.join(
|
79 |
-
filepath, "dataset_split", f"{mapping_file}_index_mapping.csv"
|
80 |
-
)
|
81 |
-
) as f:
|
82 |
-
next(f)
|
83 |
-
for i, line in enumerate(f):
|
84 |
-
subdir = "." if line.startswith("two_col") else "multiColumn"
|
85 |
-
filename = line.split("-")[1].split(".")[0]
|
86 |
-
|
87 |
-
with open(
|
88 |
-
os.path.join(filepath, subdir, "data", filename + ".csv")
|
89 |
-
) as g:
|
90 |
-
content = []
|
91 |
-
reader = csv.reader(g, delimiter=",", quotechar='"')
|
92 |
-
for row in reader:
|
93 |
-
content.append(row)
|
94 |
-
|
95 |
-
with open(
|
96 |
-
os.path.join(filepath, subdir, "captions", filename + ".txt")
|
97 |
-
) as g:
|
98 |
-
ref = g.read().rstrip("\n")
|
99 |
-
|
100 |
-
with open(
|
101 |
-
os.path.join(filepath, subdir, "titles", filename + ".txt")
|
102 |
-
) as g:
|
103 |
-
title = g.read().rstrip("\n")
|
104 |
-
|
105 |
-
data.append(
|
106 |
-
{"content": content, "ref": ref, "title": title}
|
107 |
-
)
|
108 |
-
|
109 |
-
if i % 1000 == 0:
|
110 |
-
print(f"Loaded {i} items")
|
111 |
-
|
112 |
-
for example_idx, entry in enumerate(data):
|
113 |
-
yield example_idx, {key: str(value) for key, value in entry.items()}
|
114 |
-
|
115 |
-
if __name__ == '__main__':
|
116 |
-
dataset = datasets.load_dataset(__file__)
|
117 |
-
dataset.push_to_hub("kasnerz/charttotext-s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|