chiseng-cheang commited on
Commit
3a8d406
1 Parent(s): c48fb13

Update TempoSum.py

Browse files
Files changed (1) hide show
  1. TempoSum.py +34 -12
TempoSum.py CHANGED
@@ -4,6 +4,8 @@ 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},
@@ -16,41 +18,49 @@ _DESCRIPTION = """TempoSum: Evaluating the Temporal Generalization of Abstractiv
16
 
17
  _URL = "https://huggingface.co/datasets/chiseng-cheang/TempoSum/resolve/main/data/"
18
 
 
 
 
 
19
  _DATASET_CONFIGS = {
20
  "BBC_in-distribution": {
21
  "urls": {
22
  datasets.Split.TEST: os.path.join(_URL, "bbc_in_distribution.tar.gz"),
23
  },
 
24
  },
25
  "BBC_future": {
26
  "urls": {
27
  datasets.Split.TEST: os.path.join(_URL, "bbc_future.tar.gz"),
28
  },
 
29
  },
30
  "CNN_in-distribution": {
31
  "urls": {
32
  datasets.Split.TEST: os.path.join(_URL, "cnn_in_distribution.tar.gz"),
33
  },
 
34
  },
35
  "CNN_future": {
36
  "urls": {
37
  datasets.Split.TEST: os.path.join(_URL, "cnn_future.tar.gz"),
38
  },
 
39
  },
40
  }
41
 
42
- _DOCUMENT = "document"
43
- _SUMMARY = "summary"
44
 
45
  class TempoSumConfig(datasets.BuilderConfig):
46
  """BuilderConfig for TempoSum."""
47
- def __init__(self, urls, **kwargs):
48
  super(TempoSumConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
49
  self.features = datasets.Features({
50
- _DOCUMENT: datasets.Value("string"),
51
- _SUMMARY: datasets.Value("string"),
 
52
  })
53
  self.urls = urls
 
54
 
55
  class TempoSum(datasets.GeneratorBasedBuilder):
56
  """The TempoSum benchmark."""
@@ -86,11 +96,23 @@ class TempoSum(datasets.GeneratorBasedBuilder):
86
  return splits
87
 
88
  def _generate_examples(self, data_file, split):
89
- document_path = os.path.join(data_file, _DOCUMENT)
90
- summary_path = os.path.join(data_file, _SUMMARY)
91
- with open(document_path, 'r') as document_reader, open(summary_path, 'r') as summary_reader:
92
- for idx, (document, summary) in enumerate(zip(document_reader, summary_reader)):
 
 
 
 
 
93
  yield idx, {
94
- _DOCUMENT: document,
95
- _SUMMARY: summary,
96
- }
 
 
 
 
 
 
 
 
4
  import os
5
  import datasets
6
 
7
+ from contextlib import ExitStack
8
+
9
  _CITATION = """
10
  @misc{cheang2023temposum,
11
  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},
 
18
 
19
  _URL = "https://huggingface.co/datasets/chiseng-cheang/TempoSum/resolve/main/data/"
20
 
21
+ _DOCUMENT = "document"
22
+ _SUMMARY = "summary"
23
+ _TITLE = "title"
24
+
25
  _DATASET_CONFIGS = {
26
  "BBC_in-distribution": {
27
  "urls": {
28
  datasets.Split.TEST: os.path.join(_URL, "bbc_in_distribution.tar.gz"),
29
  },
30
+ "available_features": [_DOCUMENT, _SUMMARY],
31
  },
32
  "BBC_future": {
33
  "urls": {
34
  datasets.Split.TEST: os.path.join(_URL, "bbc_future.tar.gz"),
35
  },
36
+ "available_features": [_DOCUMENT, _SUMMARY],
37
  },
38
  "CNN_in-distribution": {
39
  "urls": {
40
  datasets.Split.TEST: os.path.join(_URL, "cnn_in_distribution.tar.gz"),
41
  },
42
+ "available_features": [_DOCUMENT, _SUMMARY],
43
  },
44
  "CNN_future": {
45
  "urls": {
46
  datasets.Split.TEST: os.path.join(_URL, "cnn_future.tar.gz"),
47
  },
48
+ "available_features": [_DOCUMENT, _SUMMARY],
49
  },
50
  }
51
 
 
 
52
 
53
  class TempoSumConfig(datasets.BuilderConfig):
54
  """BuilderConfig for TempoSum."""
55
+ def __init__(self, urls, available_features, **kwargs):
56
  super(TempoSumConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
57
  self.features = datasets.Features({
58
+ feature: datasets.Value("String") for feature in available_features
59
+ # _DOCUMENT: datasets.Value("string"),
60
+ # _SUMMARY: datasets.Value("string"),
61
  })
62
  self.urls = urls
63
+ self.available_features = available_features
64
 
65
  class TempoSum(datasets.GeneratorBasedBuilder):
66
  """The TempoSum benchmark."""
 
96
  return splits
97
 
98
  def _generate_examples(self, data_file, split):
99
+ # document_path = os.path.join(data_file, _DOCUMENT)
100
+ # summary_path = os.path.join(data_file, _SUMMARY)
101
+
102
+ features = self.config.available_features
103
+ with ExitStack() as stack:
104
+ files = [stack.enter_context(open(os.path.join(data_file, feature))) \
105
+ for feature in features]
106
+
107
+ for idx, sample_data in enumerate(zip(*files)):
108
  yield idx, {
109
+ feature: feature_data \
110
+ for (feature, feature_data) in zip(features, sample_data)
111
+ }
112
+
113
+ # with open(document_path, 'r') as document_reader, open(summary_path, 'r') as summary_reader:
114
+ # for idx, (document, summary) in enumerate(zip(document_reader, summary_reader)):
115
+ # yield idx, {
116
+ # _DOCUMENT: document,
117
+ # _SUMMARY: summary,
118
+ # }