Skip to content

Commit 3343285

Browse files
authored
add Toronto BooksCorpus (#248)
* add Tornoto BooksCorpus * add forgot dummy data for Toronto BooksCorpus * Use download manager to download google drive files, thanks for Quentin Lhoest's advice. * [BookCorpus] rename bookscorpus to bookcorpus and use file from gs
1 parent 7c553db commit 3343285

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

datasets/bookcorpus/bookcorpus.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# coding=utf-8
2+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace NLP Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Lint as: python3
17+
"""The BookCorpus dataset."""
18+
19+
from __future__ import absolute_import, division, print_function
20+
21+
import glob
22+
import os
23+
import re
24+
25+
import nlp
26+
27+
_DESCRIPTION = """\
28+
Books are a rich source of both fine-grained information, how a character, \
29+
an object or a scene looks like, as well as high-level semantics, what \
30+
someone is thinking, feeling and how these states evolve through a story.\
31+
This work aims to align books to their movie releases in order to provide\
32+
rich descriptive explanations for visual content that go semantically far\
33+
beyond the captions available in current datasets. \
34+
"""
35+
36+
_CITATION = """\
37+
@InProceedings{Zhu_2015_ICCV,
38+
title = {Aligning Books and Movies: Towards Story-Like Visual Explanations by Watching Movies and Reading Books},
39+
author = {Zhu, Yukun and Kiros, Ryan and Zemel, Rich and Salakhutdinov, Ruslan and Urtasun, Raquel and Torralba, Antonio and Fidler, Sanja},
40+
booktitle = {The IEEE International Conference on Computer Vision (ICCV)},
41+
month = {December},
42+
year = {2015}
43+
}
44+
"""
45+
46+
URL = "https://storage.googleapis.com/huggingface-nlp/datasets/bookcorpus/bookcorpus.tar.bz2"
47+
48+
class BookcorpusConfig(nlp.BuilderConfig):
49+
"""BuilderConfig for BookCorpus."""
50+
51+
def __init__(self, **kwargs):
52+
"""BuilderConfig for BookCorpus.
53+
Args:
54+
**kwargs: keyword arguments forwarded to super.
55+
"""
56+
super(BookcorpusConfig, self).__init__(
57+
version=nlp.Version("1.0.0", "New split API (https://tensorflow.org/datasets/splits)"), **kwargs
58+
)
59+
60+
class Bookcorpus(nlp.GeneratorBasedBuilder):
61+
"""BookCorpus dataset."""
62+
63+
BUILDER_CONFIGS = [BookcorpusConfig(name="plain_text", description="Plain text",)]
64+
65+
def _info(self):
66+
return nlp.DatasetInfo(
67+
description=_DESCRIPTION,
68+
features=nlp.Features(
69+
{"text": nlp.Value("string"),}
70+
),
71+
supervised_keys=None,
72+
homepage="https://yknzhu.wixsite.com/mbweb",
73+
citation=_CITATION,
74+
)
75+
76+
def _vocab_text_gen(self, archive):
77+
for _, ex in self._generate_examples(archive):
78+
yield ex["text"]
79+
80+
def _split_generators(self, dl_manager):
81+
arch_path = dl_manager.download_and_extract(URL)
82+
83+
return [
84+
nlp.SplitGenerator(name=nlp.Split.TRAIN, gen_kwargs={"directory": arch_path}),
85+
]
86+
87+
def _generate_examples(self, directory):
88+
files = [os.path.join(directory, 'books_large_p1.txt'),
89+
os.path.join(directory, 'books_large_p2.txt'),]
90+
_id = 0
91+
for txt_file in files:
92+
with open(txt_file, mode="r") as f:
93+
for line in f:
94+
yield _id, {'text': line.strip()}
95+
_id += 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"plain_text": {"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 work aims to align books to their movie releases in order to providerich descriptive explanations for visual content that go semantically farbeyond the captions available in current datasets. ", "citation": "@InProceedings{Zhu_2015_ICCV,\n title = {Aligning Books and Movies: Towards Story-Like Visual Explanations by Watching Movies and Reading Books},\n author = {Zhu, Yukun and Kiros, Ryan and Zemel, Rich and Salakhutdinov, Ruslan and Urtasun, Raquel and Torralba, Antonio and Fidler, Sanja},\n booktitle = {The IEEE International Conference on Computer Vision (ICCV)},\n month = {December},\n year = {2015}\n}\n", "homepage": "https://yknzhu.wixsite.com/mbweb", "license": "", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}}, "supervised_keys": null, "builder_name": "bookcorpus", "config_name": "plain_text", "version": {"version_str": "1.0.0", "description": "New split API (https://tensorflow.org/datasets/splits)", "nlp_version_to_prepare": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 4853859824, "num_examples": 74004228, "dataset_name": "bookcorpus"}}, "download_checksums": {"https://storage.googleapis.com/huggingface-nlp/datasets/bookcorpus/bookcorpus.tar.bz2": {"num_bytes": 1179510242, "checksum": "03a29333b2b35e98a375b6ad7d2f1651835655cd348fb89c864136bce69a964c"}}, "download_size": 1179510242, "dataset_size": 4853859824, "size_in_bytes": 6033370066}}
864 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)