Andrei Panferov
commited on
Commit
•
7c5bbde
1
Parent(s):
7cc1cfb
Loader
Browse files- 2ch_b_dialogues.py +133 -0
2ch_b_dialogues.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
"""TODO: Add a description here."""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import json
|
20 |
+
import os
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
|
25 |
+
# TODO: Add BibTeX citation
|
26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
27 |
+
_CITATION = """\
|
28 |
+
@InProceedings{huggingface:dataset,
|
29 |
+
title = {2ch b dialogues},
|
30 |
+
author={black_samorez},
|
31 |
+
year={2022}
|
32 |
+
}
|
33 |
+
"""
|
34 |
+
|
35 |
+
# TODO: Add description of the dataset here
|
36 |
+
# You can copy an official description
|
37 |
+
_DESCRIPTION = """\
|
38 |
+
Dialogues build from 2ch.hk/b/ threads
|
39 |
+
"""
|
40 |
+
|
41 |
+
# TODO: Add a link to an official homepage for the dataset here
|
42 |
+
_HOMEPAGE = "2ch.hk/b/"
|
43 |
+
|
44 |
+
# TODO: Add the licence for the dataset here if you can find it
|
45 |
+
_LICENSE = ""
|
46 |
+
|
47 |
+
# TODO: Add link to the official dataset URLs here
|
48 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
49 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
50 |
+
_URLS = {
|
51 |
+
"dialogues": "https://huggingface.co/datasets/BlackSamorez/2ch_b_dialogues/blob/main/dialogues.zip",
|
52 |
+
}
|
53 |
+
|
54 |
+
|
55 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
56 |
+
class DvaChBDialogues(datasets.GeneratorBasedBuilder):
|
57 |
+
"""TODO: Short description of my dataset."""
|
58 |
+
|
59 |
+
VERSION = datasets.Version("1.0.0")
|
60 |
+
|
61 |
+
# This is an example of a dataset with multiple configurations.
|
62 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
63 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
64 |
+
|
65 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
66 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
67 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
68 |
+
|
69 |
+
# You will be able to load one or the other configurations in the following list with
|
70 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
71 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
72 |
+
BUILDER_CONFIGS = [
|
73 |
+
datasets.BuilderConfig(name="dialogues", version=VERSION, description="Collected with collect.py in May 2022"),
|
74 |
+
]
|
75 |
+
|
76 |
+
DEFAULT_CONFIG_NAME = "dialogues" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
77 |
+
|
78 |
+
def _info(self):
|
79 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
80 |
+
features = datasets.Features(
|
81 |
+
{
|
82 |
+
"dialogue": datasets.Sequence(datasets.Value("string"))
|
83 |
+
# These are the features of your dataset like images, labels ...
|
84 |
+
}
|
85 |
+
)
|
86 |
+
|
87 |
+
return datasets.DatasetInfo(
|
88 |
+
# This is the description that will appear on the datasets page.
|
89 |
+
description=_DESCRIPTION,
|
90 |
+
# This defines the different columns of the dataset and their types
|
91 |
+
features=features, # Here we define them above because they are different between the two configurations
|
92 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
93 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
94 |
+
# supervised_keys=("sentence", "label"),
|
95 |
+
# Homepage of the dataset for documentation
|
96 |
+
homepage=_HOMEPAGE,
|
97 |
+
# License for the dataset if available
|
98 |
+
license=_LICENSE,
|
99 |
+
# Citation for the dataset
|
100 |
+
citation=_CITATION,
|
101 |
+
)
|
102 |
+
|
103 |
+
def _split_generators(self, dl_manager):
|
104 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
105 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
106 |
+
|
107 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
108 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
109 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
110 |
+
urls = _URLS[self.config.name]
|
111 |
+
data_dir = dl_manager.download_and_extract(urls)
|
112 |
+
return [
|
113 |
+
datasets.SplitGenerator(
|
114 |
+
name=datasets.Split.TRAIN,
|
115 |
+
# These kwargs will be passed to _generate_examples
|
116 |
+
gen_kwargs={
|
117 |
+
"filepath": os.path.join(data_dir, "dialo.jsonl"),
|
118 |
+
"split": "train",
|
119 |
+
},
|
120 |
+
),
|
121 |
+
]
|
122 |
+
|
123 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
124 |
+
def _generate_examples(self, filepath, split):
|
125 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
126 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
127 |
+
with open(filepath, encoding="utf-8") as f:
|
128 |
+
for key, row in enumerate(f):
|
129 |
+
data = json.loads(row)
|
130 |
+
# Yields examples as (key, example) tuples
|
131 |
+
yield key, {
|
132 |
+
"dialogue": data["dialogue"],
|
133 |
+
}
|