zeio commited on
Commit
c8d1be3
1 Parent(s): 18cdd07

feat(pulled): added support for pulled dataset config

Browse files
Files changed (1) hide show
  1. pale.py +39 -7
pale.py CHANGED
@@ -1,6 +1,7 @@
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 transcribed sounds emitted by characters of the League of Legends game.
@@ -15,9 +16,12 @@ _LICENSE = 'Apache License Version 2.0'
15
  _URLS = {
16
  'full': 'https://huggingface.co/datasets/zeio/pale/resolve/main/pale.tsv',
17
  'quotes': 'https://huggingface.co/datasets/zeio/pale/resolve/main/quotes.tsv',
18
- 'annotated': 'https://huggingface.co/datasets/zeio/pale/resolve/main/annotated.tsv'
 
19
  }
20
 
 
 
21
 
22
  class Pale(GeneratorBasedBuilder):
23
 
@@ -26,7 +30,8 @@ class Pale(GeneratorBasedBuilder):
26
  BUILDER_CONFIGS = [
27
  BuilderConfig(name = 'quotes', version = VERSION, description = 'Truncated version of the corpus, which does\'t contain sound effects'),
28
  BuilderConfig(name = 'annotated', version = VERSION, description = 'An extended version of the full configuration with a couple of additional columns with labels'),
29
- BuilderConfig(name = 'vanilla', version = VERSION, description = 'All data pulled from the website without significant modifications apart from the web page structure parsing')
 
30
  ]
31
 
32
  DEFAULT_CONFIG_NAME = 'quotes'
@@ -56,6 +61,16 @@ class Pale(GeneratorBasedBuilder):
56
  'text': Value('string'),
57
  'champion': Value('string')
58
  })
 
 
 
 
 
 
 
 
 
 
59
 
60
  return DatasetInfo(
61
  description=_DESCRIPTION,
@@ -73,11 +88,28 @@ class Pale(GeneratorBasedBuilder):
73
  SplitGenerator(
74
  name = Split.TRAIN,
75
  gen_kwargs = {
76
- "path": dl_manager.download_and_extract(url)
 
77
  }
78
  )
79
  ]
80
 
81
- def _generate_examples(self, path: str):
82
  for i, row in read_csv(path, sep = '\t').iterrows():
83
- yield i, dict(row)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pandas import read_csv, NA
3
 
4
+ from datasets import GeneratorBasedBuilder, Value, Version, BuilderConfig, Features, DatasetInfo, SplitGenerator, Split, Audio
5
 
6
  _DESCRIPTION = '''
7
  This dataset contains transcribed sounds emitted by characters of the League of Legends game.
 
16
  _URLS = {
17
  'full': 'https://huggingface.co/datasets/zeio/pale/resolve/main/pale.tsv',
18
  'quotes': 'https://huggingface.co/datasets/zeio/pale/resolve/main/quotes.tsv',
19
+ 'annotated': 'https://huggingface.co/datasets/zeio/pale/resolve/main/annotated.tsv',
20
+ 'pulled': 'https://huggingface.co/datasets/zeio/pale/resolve/main/pulled.tsv'
21
  }
22
 
23
+ _SOUND_URL = 'https://huggingface.co/datasets/zeio/pale/resolve/main/sound.tar.xz'
24
+
25
 
26
  class Pale(GeneratorBasedBuilder):
27
 
 
30
  BUILDER_CONFIGS = [
31
  BuilderConfig(name = 'quotes', version = VERSION, description = 'Truncated version of the corpus, which does\'t contain sound effects'),
32
  BuilderConfig(name = 'annotated', version = VERSION, description = 'An extended version of the full configuration with a couple of additional columns with labels'),
33
+ BuilderConfig(name = 'vanilla', version = VERSION, description = 'All data pulled from the website without significant modifications apart from the web page structure parsing'),
34
+ BuilderConfig(name = 'pulled', version = VERSION, description = 'Same as vanilla, but sound files have been pulled from the website, and "source" command is replaced with "sound" column')
35
  ]
36
 
37
  DEFAULT_CONFIG_NAME = 'quotes'
 
61
  'text': Value('string'),
62
  'champion': Value('string')
63
  })
64
+ elif self.config.name == 'pulled':
65
+ features = Features({
66
+ 'header': Value('string'),
67
+ 'subheader': Value('string'),
68
+ 'text': Value('string'),
69
+ 'sound': Audio(sampling_rate = 44_100),
70
+ 'champion': Value('string')
71
+ })
72
+ else:
73
+ raise ValueError(f'Unknown config: {self.config.name}')
74
 
75
  return DatasetInfo(
76
  description=_DESCRIPTION,
 
88
  SplitGenerator(
89
  name = Split.TRAIN,
90
  gen_kwargs = {
91
+ "path": dl_manager.download_and_extract(url),
92
+ 'sound': dl_manager.download_and_extract(_SOUND_URL) if name == 'pulled' else None
93
  }
94
  )
95
  ]
96
 
97
+ def _generate_examples(self, path: str, sound: str):
98
  for i, row in read_csv(path, sep = '\t').iterrows():
99
+ if sound is None:
100
+ yield i, dict(row)
101
+ else:
102
+ data = dict(row)
103
+
104
+ folder = data['folder']
105
+ filename = data['filename']
106
+
107
+ if folder == folder and filename == filename: # if folder and filename are not nan
108
+ data['sound'] = os.path.join(sound, folder, f'{filename}.ogg')
109
+ else:
110
+ data['sound'] = NA
111
+
112
+ data.pop('folder')
113
+ data.pop('filename')
114
+
115
+ yield i, data