lara-martin
commited on
Commit
·
c9930d6
1
Parent(s):
b52f3c4
Update Scifi_TV_Shows.py
Browse files- Scifi_TV_Shows.py +38 -37
Scifi_TV_Shows.py
CHANGED
@@ -33,13 +33,7 @@ url={https://ojs.aaai.org//index.php/AAAI/article/view/6232}
|
|
33 |
|
34 |
_DESCRIPTION = 'Loading script for the science fiction TV show plot dataset.'
|
35 |
|
36 |
-
|
37 |
-
_URLS = {
|
38 |
-
'test':URL+'Test-Train-Val/all-sci-fi-data-test.txt',
|
39 |
-
'train':URL+'Test-Train-Val/all-sci-fi-data-train.txt',
|
40 |
-
'val':URL+'Test-Train-Val/all-sci-fi-data-val.txt',
|
41 |
-
'all':URL+'all-sci-fi-data.txt',
|
42 |
-
}
|
43 |
|
44 |
_INPUT_OUTPUT = ["all-sci-fi-data-test_input.txt", "all-sci-fi-data-test_output.txt", "all-sci-fi-data-train_input.txt", "all-sci-fi-data-train_output.txt", "all-sci-fi-data-val_input.txt", "all-sci-fi-data-val_output.txt"]
|
45 |
|
@@ -78,62 +72,69 @@ class Scifi_TV_Shows(datasets.GeneratorBasedBuilder):
|
|
78 |
)
|
79 |
|
80 |
def _split_generators(self, dl_manager):
|
81 |
-
|
|
|
82 |
return[
|
83 |
datasets.SplitGenerator(
|
84 |
name=datasets.Split.TRAIN,
|
85 |
gen_kwargs={
|
86 |
-
'filepath':
|
87 |
"split": "train",
|
|
|
88 |
},
|
89 |
),
|
90 |
datasets.SplitGenerator(
|
91 |
name=datasets.Split.TEST,
|
92 |
gen_kwargs={
|
93 |
-
'filepath':
|
94 |
"split": "test",
|
|
|
95 |
},
|
96 |
),
|
97 |
datasets.SplitGenerator(
|
98 |
name=datasets.Split.VALIDATION,
|
99 |
gen_kwargs={
|
100 |
-
'filepath':
|
101 |
"split": "val",
|
|
|
102 |
},
|
103 |
),
|
104 |
datasets.SplitGenerator(
|
105 |
name="all",
|
106 |
gen_kwargs={
|
107 |
-
'filepath':
|
108 |
"split": "all",
|
|
|
109 |
},
|
110 |
),
|
111 |
]
|
112 |
|
113 |
-
def _generate_examples(self, filepath):
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
138 |
|
139 |
|
|
|
33 |
|
34 |
_DESCRIPTION = 'Loading script for the science fiction TV show plot dataset.'
|
35 |
|
36 |
+
_URLS = {'Scifi_TV_Shows': "https://huggingface.co/datasets/lara-martin/Scifi_TV_Shows/resolve/main/scifiTVshows.zip"}
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
_INPUT_OUTPUT = ["all-sci-fi-data-test_input.txt", "all-sci-fi-data-test_output.txt", "all-sci-fi-data-train_input.txt", "all-sci-fi-data-train_output.txt", "all-sci-fi-data-val_input.txt", "all-sci-fi-data-val_output.txt"]
|
39 |
|
|
|
72 |
)
|
73 |
|
74 |
def _split_generators(self, dl_manager):
|
75 |
+
my_urls = _URLS[self.config.name]
|
76 |
+
archive = dl_manager.download(my_urls)
|
77 |
return[
|
78 |
datasets.SplitGenerator(
|
79 |
name=datasets.Split.TRAIN,
|
80 |
gen_kwargs={
|
81 |
+
'filepath': "all-sci-fi-data-train.txt",
|
82 |
"split": "train",
|
83 |
+
"files": dl_manager.iter_archive(archive),
|
84 |
},
|
85 |
),
|
86 |
datasets.SplitGenerator(
|
87 |
name=datasets.Split.TEST,
|
88 |
gen_kwargs={
|
89 |
+
'filepath': "all-sci-fi-data-test.txt"
|
90 |
"split": "test",
|
91 |
+
"files": dl_manager.iter_archive(archive),
|
92 |
},
|
93 |
),
|
94 |
datasets.SplitGenerator(
|
95 |
name=datasets.Split.VALIDATION,
|
96 |
gen_kwargs={
|
97 |
+
'filepath': "all-sci-fi-data-val.txt",
|
98 |
"split": "val",
|
99 |
+
"files": dl_manager.iter_archive(archive),
|
100 |
},
|
101 |
),
|
102 |
datasets.SplitGenerator(
|
103 |
name="all",
|
104 |
gen_kwargs={
|
105 |
+
'filepath': "all-sci-fi-data.txt",
|
106 |
"split": "all",
|
107 |
+
"files": dl_manager.iter_archive(archive),
|
108 |
},
|
109 |
),
|
110 |
]
|
111 |
|
112 |
+
def _generate_examples(self, filepath, files):
|
113 |
+
for path, f in files:
|
114 |
+
if path == filepath:
|
115 |
+
story_count = 0
|
116 |
+
with open(filepath, encoding="utf-8") as f:
|
117 |
+
story = []
|
118 |
+
for id_, line in enumerate(f.readlines()):
|
119 |
+
line = line.strip()
|
120 |
+
if "%%%%%%" in line:
|
121 |
+
for l in story:
|
122 |
+
event, gen_event, sent, gen_sent = l.split("|||")
|
123 |
+
line = line.replace("%%%%%%%%%%%%%%%%%", "")
|
124 |
+
entities = line.replace("defaultdict(<type 'list'>, ", "")[:-1]
|
125 |
+
yield id_, {
|
126 |
+
'story_num': story_count,
|
127 |
+
'event': eval(event),
|
128 |
+
'gen_event': eval(gen_event),
|
129 |
+
'sent': sent,
|
130 |
+
'gen_sent': gen_sent,
|
131 |
+
'entities': entities,
|
132 |
+
}
|
133 |
+
story = []
|
134 |
+
story_count+=1
|
135 |
+
elif "<EOS>" in line:
|
136 |
+
continue
|
137 |
+
else:
|
138 |
+
story.append(line)
|
139 |
|
140 |
|