|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
_CITATION = ''' |
|
@inproceedings{Ammanabrolu2020AAAI, |
|
title={Story Realization: Expanding Plot Events into Sentences}, |
|
author={Prithviraj Ammanabrolu and Ethan Tien and Wesley Cheung and Zhaochen Luo and William Ma and Lara J. Martin and Mark O. Riedl}, |
|
journal={Proceedings of the AAAI Conference on Artificial Intelligence (AAAI)}, |
|
year={2020}, |
|
volume={34}, |
|
number={05}, |
|
url={https://ojs.aaai.org//index.php/AAAI/article/view/6232} |
|
} |
|
''' |
|
|
|
_DESCRIPTION = 'Loading script for the science fiction TV show plot dataset.' |
|
|
|
_URLS = {'Scifi_TV_Shows': "https://huggingface.co/datasets/lara-martin/Scifi_TV_Shows/resolve/main/scifiTVshows.zip"} |
|
|
|
|
|
class Scifi_TV_Shows(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
version=datasets.Version('1.1.0'), |
|
name="Scifi_TV_Shows", |
|
description=f'Science fiction TV show plot summaries.', |
|
) |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features({ |
|
'story_num': datasets.Value('int16'), |
|
'event': datasets.Sequence(datasets.Value('string')), |
|
'gen_event': datasets.Sequence(datasets.Value('string')), |
|
'sent': datasets.Value('string'), |
|
'gen_sent': datasets.Value('string'), |
|
'entities': datasets.Value('string'), |
|
}) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
supervised_keys=None, |
|
|
|
homepage='https://github.com/rajammanabrolu/StoryRealization', |
|
|
|
license='The Creative Commons Attribution 4.0 International License. https://creativecommons.org/licenses/by/4.0/', |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
my_urls = _URLS[self.config.name] |
|
archive = dl_manager.download(my_urls) |
|
return[ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
'filepath': "all-sci-fi-data-train.txt", |
|
"split": "train", |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
'filepath': "all-sci-fi-data-test.txt" |
|
"split": "test", |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
'filepath': "all-sci-fi-data-val.txt", |
|
"split": "val", |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name="all", |
|
gen_kwargs={ |
|
'filepath': "all-sci-fi-data.txt", |
|
"split": "all", |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, files): |
|
for path, f in files: |
|
if path == filepath: |
|
story_count = 0 |
|
with open(filepath, encoding="utf-8") as f: |
|
story = [] |
|
for id_, line in enumerate(f.readlines()): |
|
line = line.strip() |
|
if "%%%%%%" in line: |
|
for l in story: |
|
event, gen_event, sent, gen_sent = l.split("|||") |
|
line = line.replace("%%%%%%%%%%%%%%%%%", "") |
|
entities = line.replace("defaultdict(<type 'list'>, ", "")[:-1] |
|
yield id_, { |
|
'story_num': story_count, |
|
'event': eval(event), |
|
'gen_event': eval(gen_event), |
|
'sent': sent, |
|
'gen_sent': gen_sent, |
|
'entities': entities, |
|
} |
|
story = [] |
|
story_count+=1 |
|
elif "<EOS>" in line: |
|
continue |
|
else: |
|
story.append(line) |
|
|
|
|
|
|