Daniel Campos commited on
Commit
071cbf5
1 Parent(s): da75d78

Create new file

Browse files
Files changed (1) hide show
  1. cc-stories.py +99 -0
cc-stories.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ # Lint as: python3
15
+ """The Stories CC dataset."""
16
+
17
+ import datasets
18
+
19
+
20
+ _DESCRIPTION = """\
21
+ CC-Stories (or STORIES) is a dataset for common sense reasoning and language modeling. It was constructed by aggregating documents from the CommonCrawl dataset that has the most overlapping n-grams with the questions in commonsense reasoning tasks. The top 1.0% of highest ranked documents is chosen as the new training corpus.
22
+ """
23
+
24
+ _CITATION = """\
25
+ @article{Trinh2018ASM,
26
+ title={A Simple Method for Commonsense Reasoning},
27
+ author={Trieu H. Trinh and Quoc V. Le},
28
+ journal={ArXiv},
29
+ year={2018},
30
+ volume={abs/1806.02847}
31
+ }
32
+ """
33
+
34
+
35
+ URL = "https://huggingface.co/datasets/spacemanidol/cc-stories/resolve/main/cc-stories.txt.gz"
36
+
37
+ _DATASET_URLS = {
38
+ 'all': "https://huggingface.co/datasets/spacemanidol/cc-stories/resolve/main/cc-stories.txt.gz",
39
+ 'dev': "https://huggingface.co/datasets/spacemanidol/cc-stories/resolve/main/cc-stories-dev.txt.gz",
40
+ 'test': "https://huggingface.co/datasets/spacemanidol/cc-stories/resolve/main/cc-stories-test.txt.gz",
41
+ 'train': "https://huggingface.co/datasets/spacemanidol/cc-stories/resolve/main/cc-stories-train.txt.gz"
42
+ }
43
+
44
+ class CCStoriesConfig(datasets.BuilderConfig):
45
+ """BuilderConfig for CC Stories."""
46
+
47
+ def __init__(self, **kwargs):
48
+ """BuilderConfig for CC Stories
49
+ Args:
50
+ **kwargs: keyword arguments forwarded to super.
51
+ """
52
+ super(CCStoriesConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
53
+
54
+
55
+ class Bookcorpus(datasets.GeneratorBasedBuilder):
56
+ """CC Stories dataset."""
57
+
58
+ BUILDER_CONFIGS = [
59
+ CCStoriesConfig(
60
+ name="plain_text",
61
+ description="Plain text",
62
+ )
63
+ ]
64
+
65
+ def _info(self):
66
+ return datasets.DatasetInfo(
67
+ description=_DESCRIPTION,
68
+ features=datasets.Features(
69
+ {
70
+ "text": datasets.Value("string"),
71
+ }
72
+ ),
73
+ supervised_keys=None,
74
+ homepage="",
75
+ citation=_CITATION,
76
+ )
77
+
78
+ def _vocab_text_gen(self, archive):
79
+ for _, ex in self._generate_examples(archive):
80
+ yield ex["text"]
81
+
82
+ def _split_generators(self, dl_manager):
83
+ downloaded_files = dl_manager.download_and_extract(_DATASET_URLS)
84
+ splits = [
85
+ datasets.SplitGenerator(
86
+ name=split,
87
+ gen_kwargs={
88
+ "files": [downloaded_files[split]] if isinstance(downloaded_files[split], str) else downloaded_files[split],
89
+ },
90
+ ) for split in downloaded_files
91
+ ]
92
+ return splits
93
+
94
+ def _generate_examples(self, files):
95
+ _id = 0
96
+ for path, file in files:
97
+ for line in file:
98
+ yield _id, {"text": line.decode("utf-8").strip()}
99
+ _id += 1