Datasets:
vladsaveliev
commited on
Commit
•
4a3121a
1
Parent(s):
63e7ca3
Add headers to the examples
Browse files- .gitignore +1 -0
- README.md +16 -6
- guitar_tab.py +68 -67
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
.DS_Store
|
|
|
|
1 |
.DS_Store
|
2 |
+
.idea
|
README.md
CHANGED
@@ -11,12 +11,8 @@ size_categories:
|
|
11 |
dataset_info:
|
12 |
- config_name: default
|
13 |
features:
|
14 |
-
- name: file
|
15 |
-
dtype: string
|
16 |
- name: text
|
17 |
dtype: string
|
18 |
-
- name: title
|
19 |
-
dtype: string
|
20 |
- name: track_name
|
21 |
dtype: string
|
22 |
- name: track_number
|
@@ -25,18 +21,32 @@ dataset_info:
|
|
25 |
dtype: string
|
26 |
- name: instrument_number
|
27 |
dtype: int32
|
|
|
|
|
28 |
- name: tempo
|
29 |
dtype: int32
|
30 |
- name: tuning
|
31 |
dtype: string
|
32 |
- name: frets
|
33 |
dtype: int32
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
splits:
|
35 |
- name: train
|
36 |
-
num_bytes:
|
37 |
num_examples: 188297
|
38 |
download_size: 75369951
|
39 |
-
dataset_size:
|
40 |
- config_name: all
|
41 |
features:
|
42 |
- name: file
|
|
|
11 |
dataset_info:
|
12 |
- config_name: default
|
13 |
features:
|
|
|
|
|
14 |
- name: text
|
15 |
dtype: string
|
|
|
|
|
16 |
- name: track_name
|
17 |
dtype: string
|
18 |
- name: track_number
|
|
|
21 |
dtype: string
|
22 |
- name: instrument_number
|
23 |
dtype: int32
|
24 |
+
- name: title
|
25 |
+
dtype: string
|
26 |
- name: tempo
|
27 |
dtype: int32
|
28 |
- name: tuning
|
29 |
dtype: string
|
30 |
- name: frets
|
31 |
dtype: int32
|
32 |
+
- name: file
|
33 |
+
dtype: string
|
34 |
+
- name: subtitle
|
35 |
+
dtype: string
|
36 |
+
- name: artist
|
37 |
+
dtype: string
|
38 |
+
- name: album
|
39 |
+
dtype: string
|
40 |
+
- name: words
|
41 |
+
dtype: string
|
42 |
+
- name: music
|
43 |
+
dtype: string
|
44 |
splits:
|
45 |
- name: train
|
46 |
+
num_bytes: 955323858
|
47 |
num_examples: 188297
|
48 |
download_size: 75369951
|
49 |
+
dataset_size: 955323858
|
50 |
- config_name: all
|
51 |
features:
|
52 |
- name: file
|
guitar_tab.py
CHANGED
@@ -1,10 +1,12 @@
|
|
|
|
1 |
import itertools
|
2 |
from pathlib import Path
|
|
|
|
|
3 |
import datasets
|
4 |
|
5 |
datasets.logging.set_verbosity_info()
|
6 |
|
7 |
-
|
8 |
_DESCRIPTION = """\
|
9 |
Dataset of music tablature, in alphaTex (https://alphatab.net/docs/alphatex)
|
10 |
format, converted from Guitar Pro files (gp3, gp4, gp5, which are downloaded
|
@@ -143,32 +145,37 @@ INSTRUMENT_MAP = {
|
|
143 |
}
|
144 |
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
class Builder(datasets.GeneratorBasedBuilder):
|
147 |
-
VERSION = datasets.Version("1.
|
148 |
|
149 |
def _info(self):
|
150 |
return datasets.DatasetInfo(
|
151 |
description=_DESCRIPTION,
|
152 |
features=datasets.Features(
|
153 |
{
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
"track_number": datasets.Value("int32"),
|
159 |
-
"instrument_name": datasets.Value("string"),
|
160 |
-
"instrument_number": datasets.Value("int32"),
|
161 |
-
"tempo": datasets.Value("int32"),
|
162 |
-
"tuning": datasets.Value("string"),
|
163 |
-
"frets": datasets.Value("int32"),
|
164 |
-
# "subtitle": datasets.Value("string"),
|
165 |
-
# "artist": datasets.Value("string"),
|
166 |
-
# "album": datasets.Value("string"),
|
167 |
-
# "words": datasets.Value("string"),
|
168 |
-
# "music": datasets.Value("string"),
|
169 |
-
# "copyright": datasets.Value("string"),
|
170 |
-
# "tab": datasets.Value("string"),
|
171 |
-
# "instructions": datasets.Value("string"),
|
172 |
}
|
173 |
),
|
174 |
)
|
@@ -194,39 +201,30 @@ class Builder(datasets.GeneratorBasedBuilder):
|
|
194 |
with open(path) as f:
|
195 |
examples = _parse_examples(f.read())
|
196 |
for example in examples:
|
197 |
-
example
|
198 |
-
yield f"{idx}-{example
|
199 |
|
200 |
|
201 |
-
def _parse_examples(tex):
|
202 |
"""
|
203 |
Returns a dictionary for each track
|
204 |
"""
|
205 |
-
|
206 |
-
|
207 |
-
"file": None,
|
208 |
-
"title": None,
|
209 |
-
"track_name": None,
|
210 |
-
"track_number": None,
|
211 |
-
"instrument_name": None,
|
212 |
-
"instrument_number": None,
|
213 |
-
"tempo": None,
|
214 |
-
"tuning": None,
|
215 |
-
"frets": None,
|
216 |
-
}
|
217 |
-
tracks = [tmpl.copy()]
|
218 |
|
219 |
def _parse_track_header(k, v):
|
220 |
if k == "instrument":
|
221 |
-
|
222 |
-
|
223 |
elif k == "tuning":
|
224 |
-
|
225 |
elif k == "frets":
|
226 |
-
|
227 |
|
228 |
-
lines = (
|
229 |
-
|
|
|
|
|
230 |
assert line.startswith("\\")
|
231 |
line = line.lstrip("\\")
|
232 |
kv = line.split(" ", 1)
|
@@ -235,44 +233,47 @@ def _parse_examples(tex):
|
|
235 |
k, v = kv
|
236 |
if k in [
|
237 |
"title",
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
# "copyright",
|
244 |
-
# "tab",
|
245 |
-
# "instructions",
|
246 |
]:
|
247 |
-
|
248 |
elif k == "tempo":
|
249 |
-
|
250 |
else:
|
251 |
_parse_track_header(k, v)
|
252 |
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
for line in lines:
|
255 |
if line.startswith("\\"):
|
256 |
-
|
257 |
-
kv = line.split(" ", 1)
|
258 |
-
if len(kv) == 2:
|
259 |
k = kv[0]
|
260 |
v = kv[1].strip('"').strip("'")
|
261 |
else:
|
262 |
k = kv[0]
|
263 |
v = None
|
264 |
if k == "track":
|
265 |
-
|
266 |
-
tracks[-1]["text"] = " ".join(track_lines)
|
267 |
-
track_lines = []
|
268 |
-
tracks.append(tmpl.copy())
|
269 |
-
track_number = len(tracks) + 1
|
270 |
-
tracks[-1]["track_number"] = track_number
|
271 |
-
tracks[-1]["track_name"] = v if v else f"Track {track_number}"
|
272 |
else:
|
273 |
_parse_track_header(k, v)
|
274 |
else:
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
return [t for t in tracks if t["text"]]
|
|
|
1 |
+
import dataclasses
|
2 |
import itertools
|
3 |
from pathlib import Path
|
4 |
+
from typing import List
|
5 |
+
|
6 |
import datasets
|
7 |
|
8 |
datasets.logging.set_verbosity_info()
|
9 |
|
|
|
10 |
_DESCRIPTION = """\
|
11 |
Dataset of music tablature, in alphaTex (https://alphatab.net/docs/alphatex)
|
12 |
format, converted from Guitar Pro files (gp3, gp4, gp5, which are downloaded
|
|
|
145 |
}
|
146 |
|
147 |
|
148 |
+
@dataclasses.dataclass
|
149 |
+
class Example:
|
150 |
+
text: str
|
151 |
+
track_name: str
|
152 |
+
track_number: int
|
153 |
+
instrument_name: str
|
154 |
+
instrument_number: int
|
155 |
+
title: str = None
|
156 |
+
tempo: int = None
|
157 |
+
tuning: str = None
|
158 |
+
frets: int = None
|
159 |
+
file: str = None
|
160 |
+
subtitle: str = None
|
161 |
+
artist: str = None
|
162 |
+
album: str = None
|
163 |
+
words: str = None
|
164 |
+
music: str = None
|
165 |
+
|
166 |
+
|
167 |
class Builder(datasets.GeneratorBasedBuilder):
|
168 |
+
VERSION = datasets.Version("1.4.0")
|
169 |
|
170 |
def _info(self):
|
171 |
return datasets.DatasetInfo(
|
172 |
description=_DESCRIPTION,
|
173 |
features=datasets.Features(
|
174 |
{
|
175 |
+
field: datasets.Value("int32")
|
176 |
+
if type_ == int
|
177 |
+
else datasets.Value("string")
|
178 |
+
for field, type_ in Example.__annotations__.items()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
}
|
180 |
),
|
181 |
)
|
|
|
201 |
with open(path) as f:
|
202 |
examples = _parse_examples(f.read())
|
203 |
for example in examples:
|
204 |
+
example.file = path.name
|
205 |
+
yield f"{idx}-{example.track_number}", example.__dict__
|
206 |
|
207 |
|
208 |
+
def _parse_examples(tex: str) -> List[Example]:
|
209 |
"""
|
210 |
Returns a dictionary for each track
|
211 |
"""
|
212 |
+
examples = []
|
213 |
+
data = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
def _parse_track_header(k, v):
|
216 |
if k == "instrument":
|
217 |
+
data['instrument_name'] = INSTRUMENT_MAP.get(int(v), "unknown")
|
218 |
+
data['instrument_number'] = int(v)
|
219 |
elif k == "tuning":
|
220 |
+
data['tuning'] = v.split(" ")
|
221 |
elif k == "frets":
|
222 |
+
data['frets'] = int(v)
|
223 |
|
224 |
+
lines = (l_.strip() for l_ in tex.splitlines() if l_.strip())
|
225 |
+
header_lines = list(itertools.takewhile(lambda l: l != ".", lines))
|
226 |
+
|
227 |
+
for line in header_lines:
|
228 |
assert line.startswith("\\")
|
229 |
line = line.lstrip("\\")
|
230 |
kv = line.split(" ", 1)
|
|
|
233 |
k, v = kv
|
234 |
if k in [
|
235 |
"title",
|
236 |
+
"subtitle",
|
237 |
+
"artist",
|
238 |
+
"album",
|
239 |
+
"words",
|
240 |
+
"music",
|
|
|
|
|
|
|
241 |
]:
|
242 |
+
data[k] = v.strip('"').strip("'")
|
243 |
elif k == "tempo":
|
244 |
+
data['tempo'] = int(v)
|
245 |
else:
|
246 |
_parse_track_header(k, v)
|
247 |
|
248 |
+
track_header_lines = []
|
249 |
+
track_tex_lines = []
|
250 |
+
|
251 |
+
def _add_example():
|
252 |
+
nonlocal data, track_header_lines, track_tex_lines
|
253 |
+
if track_tex_lines:
|
254 |
+
data['track_number'] = (track_number := len(examples) + 1)
|
255 |
+
data['track_name'] = v if v else f"Track {track_number}"
|
256 |
+
data['text'] = (
|
257 |
+
'\n'.join(track_header_lines + [" ".join(track_tex_lines)])
|
258 |
+
)
|
259 |
+
examples.append(Example(**data))
|
260 |
+
data = {}
|
261 |
+
track_header_lines = []
|
262 |
+
track_tex_lines = []
|
263 |
+
|
264 |
for line in lines:
|
265 |
if line.startswith("\\"):
|
266 |
+
if len(kv := line.lstrip("\\").split(" ", 1)) == 2:
|
|
|
|
|
267 |
k = kv[0]
|
268 |
v = kv[1].strip('"').strip("'")
|
269 |
else:
|
270 |
k = kv[0]
|
271 |
v = None
|
272 |
if k == "track":
|
273 |
+
_add_example()
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
else:
|
275 |
_parse_track_header(k, v)
|
276 |
else:
|
277 |
+
track_tex_lines.append(line)
|
278 |
+
_add_example()
|
279 |
+
return [t for t in examples if t.text]
|
|