zeio commited on
Commit
c73b4b4
1 Parent(s): 687f3d2

feat(loader): added dataset loader

Browse files
Files changed (1) hide show
  1. baneks.py +65 -0
baneks.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pandas import read_csv
2
+
3
+ from datasets import GeneratorBasedBuilder, Value, Version, BuilderConfig, Features, DatasetInfo, SplitGenerator, Split
4
+
5
+ _DESCRIPTION = '''
6
+ This dataset contains anekdotes parsed from a few vk social network communities. The data can be useful for fine-tuning language generation models as well for tasks of automatic humour analysis.
7
+ '''
8
+
9
+ _HOMEPAGE = 'https://huggingface.co/datasets/zeio/baneks'
10
+
11
+ _LICENSE = 'Apache License Version 2.0'
12
+
13
+ _URLS = {
14
+ 'censored': 'https://huggingface.co/datasets/zeio/baneks/resolve/main/censored.tsv',
15
+ 'default': 'https://huggingface.co/datasets/zeio/baneks/resolve/main/default.tsv',
16
+ 'inflated': 'https://huggingface.co/datasets/zeio/baneks/resolve/main/inflated.tsv'
17
+ }
18
+
19
+
20
+ class Baneks(GeneratorBasedBuilder):
21
+
22
+ VERSION = Version('10.10.2023')
23
+
24
+ BUILDER_CONFIGS = [
25
+ BuilderConfig(name = 'censored', version = VERSION, description = 'No duplicates - entries with the same text are grouped and aggregated'),
26
+ BuilderConfig(name = 'default', version = VERSION, description = 'Same as "censored", but censored words are replaced with inferred values for their initial form'),
27
+ BuilderConfig(name = 'inflated', version = VERSION, description = 'Each entry corresponds to a post, minimal changes to the source data')
28
+ ]
29
+
30
+ DEFAULT_CONFIG_NAME = 'default'
31
+
32
+ def _info(self):
33
+ return DatasetInfo(
34
+ description=_DESCRIPTION,
35
+ features = Features({
36
+ 'text': Value('string'),
37
+ 'published': Value('string'),
38
+ 'id': Value('int32'),
39
+ 'n-likes': Value('int32'),
40
+ 'n-views': Value('int32'),
41
+ 'accessed': Value('string'),
42
+ 'source': Value('string')
43
+ }),
44
+ homepage=_HOMEPAGE,
45
+ license=_LICENSE
46
+ )
47
+
48
+ def _split_generators(self, dl_manager):
49
+ name = self.config.name
50
+
51
+ url = _URLS[name]
52
+ # path = os.path.join(dl_manager.download_and_extract(url), f'{name}.tsv')
53
+
54
+ return [
55
+ SplitGenerator(
56
+ name = Split.TRAIN,
57
+ gen_kwargs = {
58
+ "path": dl_manager.download_and_extract(url)
59
+ }
60
+ )
61
+ ]
62
+
63
+ def _generate_examples(self, path: str):
64
+ for _, row in read_csv(path, sep = '\t').iterrows():
65
+ yield f'{row["id"]:08d}-{row["source"]}', dict(row)