Datasets:
File size: 4,125 Bytes
4c153aa 33ef343 4c153aa 817f291 4c153aa 8bf99c5 d5e3dac 4c153aa 33ef343 4c153aa 817f291 4c153aa 33ef343 4c153aa 33ef343 4c153aa 33ef343 4c153aa 33ef343 4c153aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
"""The BookCorpus dataset based on Shawn Presser's work https://github.com/soskek/bookcorpus/issues/27 """
import os
from fnmatch import fnmatch
import datasets
from datasets.exceptions import DefunctDatasetError
_DESCRIPTION = """\
Books are a rich source of both fine-grained information, how a character, \
an object or a scene looks like, as well as high-level semantics, what \
someone is thinking, feeling and how these states evolve through a story.\
This version of bookcorpus has 17868 dataset items (books). Each item contains \
two fields: title and text. The title is the name of the book (just the file name) \
while text contains unprocessed book text. The bookcorpus has been prepared by \
Shawn Presser and is generously hosted by The-Eye. The-Eye is a non-profit, community \
driven platform dedicated to the archiving and long-term preservation of any and \
all data including but by no means limited to... websites, books, games, software, \
video, audio, other digital-obscura and ideas.
"""
_CITATION = """\
@InProceedings{Zhu_2015_ICCV,
title = {Aligning Books and Movies: Towards Story-Like Visual Explanations by Watching Movies and Reading Books},
author = {Zhu, Yukun and Kiros, Ryan and Zemel, Rich and Salakhutdinov, Ruslan and Urtasun, Raquel and Torralba, Antonio and Fidler, Sanja},
booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
month = {December},
year = {2015}
}
"""
_PROJECT_URL = "https://github.com/soskek/bookcorpus/issues/27"
_HOST_URL = "https://the-eye.eu"
_DOWNLOAD_URL = f"{_HOST_URL}/public/AI/pile_preliminary_components/books1.tar.gz"
class BookCorpusOpenConfig(datasets.BuilderConfig):
"""BuilderConfig for BookCorpus."""
def __init__(self, **kwargs):
"""BuilderConfig for BookCorpus.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(BookCorpusOpenConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
class BookCorpusOpen(datasets.GeneratorBasedBuilder):
"""BookCorpus dataset."""
DEFAULT_WRITER_BATCH_SIZE = 256 # documents are full books and are quite heavy
BUILDER_CONFIGS = [
BookCorpusOpenConfig(
name="plain_text",
description="Plain text",
)
]
def _info(self):
raise DefunctDatasetError(
"Dataset 'bookcorpusopen' is defunct and no longer accessible due to unavailability of the source data"
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"title": datasets.Value("string"),
"text": datasets.Value("string"),
}
),
supervised_keys=None,
homepage=_PROJECT_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
archive = dl_manager.download(_DOWNLOAD_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN, gen_kwargs={"book_files": dl_manager.iter_archive(archive)}
),
]
def _generate_examples(self, book_files):
_id = 0
for book_file_path, f in book_files:
name = os.path.basename(book_file_path)
if fnmatch(name, "*.epub.txt"):
yield _id, {"title": name, "text": f.read().decode("utf-8")},
_id += 1
|