chiseng-cheang commited on
Commit
27b2113
1 Parent(s): a271c5c

Create TempoSum.py

Browse files
Files changed (1) hide show
  1. TempoSum.py +95 -0
TempoSum.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The TempoSum benchmark."""
2
+
3
+ import json
4
+ import os
5
+ import datasets
6
+
7
+ _CITATION = """
8
+ @misc{cheang2023temposum,
9
+ Author = {Chi Seng Cheang and Hou Pong Chan and Derek F. Wong and Xuebo Liu and Zhaocong Li and Yanming Sun and Shudong Liu and Lidia S. Chao},
10
+ Title = {TempoSum: Evaluating the Temporal Generalization of Abstractive Summarization},
11
+ Year = {2023},
12
+ """
13
+
14
+ _DESCRIPTION = """TempoSum: Evaluating the Temporal Generalization of Abstractive Summarization"""
15
+
16
+ _URL = "https://huggingface.co/datasets/chiseng-cheang/TempoSum/tree/main/data"
17
+
18
+ _DATASET_CONFIGS = {
19
+ "BBC_in-distribution": {
20
+ "urls": {
21
+ datasets.Split.TEST: os.path.join(_URL, "bbc_in_distribution.tar.gz"),
22
+ },
23
+ },
24
+ "BBC_future": {
25
+ "urls": {
26
+ datasets.Split.TEST: os.path.join(_URL, "bbc_future.tar.gz"),
27
+ },
28
+ },
29
+ "CNN_in-distribution": {
30
+ "urls": {
31
+ datasets.Split.TEST: os.path.join(_URL, "cnn_in_distribution.tar.gz"),
32
+ },
33
+ },
34
+ "CNN_future": {
35
+ "urls": {
36
+ datasets.Split.TEST: os.path.join(_URL, "cnn_future.tar.gz"),
37
+ },
38
+ },
39
+ }
40
+
41
+ _DOCUMENT = "document"
42
+ _SUMMARY = "summary"
43
+
44
+ class TempoSumConfig(datasets.BuilderConfig):
45
+ """BuilderConfig for TempoSum."""
46
+ def __init__(self, urls, **kwargs):
47
+ super(TempoSumConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
48
+ self.features = datasets.Features({
49
+ _DOCUMENT: datasets.Value("string"),
50
+ _SUMMARY: datasets.Value("string"),
51
+ })
52
+ self.urls = urls
53
+
54
+ class TempoSum(datasets.GeneratorBasedBuilder):
55
+ """The TempoSum benchmark."""
56
+ BUILDER_CONFIGS = []
57
+
58
+ for datasplit_name, datasplit_config in _DATASET_CONFIGS.items():
59
+ BUILDER_CONFIGS.append(
60
+ TempoSumConfig(
61
+ name=datasplit_name,
62
+ urls=datasplit_config['urls'],
63
+ )
64
+ )
65
+
66
+ def _info(self):
67
+ return datasets.DatasetInfo(
68
+ description=_DESCRIPTION,
69
+ homepage="https://github.com/AndyCheang/TempoSum",
70
+ )
71
+
72
+ def _split_generators(self, dl_manager):
73
+ dl_dirs = dl_manager.download_and_extract(self.config.urls)
74
+ splits = []
75
+ for split in dl_dirs:
76
+ splits.append(
77
+ datasets.SplitGenerator(
78
+ name=split._name,
79
+ gen_kwargs={
80
+ 'data_file': dl_dirs[split],
81
+ 'split': split,
82
+ }
83
+ )
84
+ )
85
+ return splits
86
+
87
+ def _generate_examples(self, data_file, split):
88
+ document_path = os.path.join(data_file, _DOCUMENT)
89
+ summary_path = os.path.join(data_file, _SUMMARY)
90
+ with open(document_path, 'r') as document_reader, open(summary_path, 'r') as summary_reader:
91
+ for idx, (document, summary) in enumerate(zip(document_reader, summary_reader)):
92
+ yield idx, {
93
+ _DOCUMENT: document,
94
+ _SUMMARY: summary,
95
+ }