[update]add main
Browse files- music.jsonl → data/music.jsonl +0 -0
- main.py +16 -0
- music_comment.py +103 -0
music.jsonl → data/music.jsonl
RENAMED
File without changes
|
main.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
from datasets import load_dataset
|
4 |
+
|
5 |
+
dataset = load_dataset(
|
6 |
+
"music_comment.py",
|
7 |
+
name="music_comment",
|
8 |
+
split="train",
|
9 |
+
)
|
10 |
+
|
11 |
+
for sample in dataset:
|
12 |
+
print(sample)
|
13 |
+
|
14 |
+
|
15 |
+
if __name__ == '__main__':
|
16 |
+
pass
|
music_comment.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
from glob import glob
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
from pathlib import Path
|
7 |
+
|
8 |
+
import datasets
|
9 |
+
|
10 |
+
|
11 |
+
_URLS = {
|
12 |
+
"music_comment": "data/music.jsonl",
|
13 |
+
}
|
14 |
+
|
15 |
+
|
16 |
+
_CITATION = """\
|
17 |
+
@dataset{music_comment,
|
18 |
+
author = {Xing Tian},
|
19 |
+
title = {music_comment},
|
20 |
+
month = sep,
|
21 |
+
year = 2023,
|
22 |
+
publisher = {Xing Tian},
|
23 |
+
version = {1.0},
|
24 |
+
}
|
25 |
+
"""
|
26 |
+
|
27 |
+
|
28 |
+
class MusicComment(datasets.GeneratorBasedBuilder):
|
29 |
+
VERSION = datasets.Version("1.0.0")
|
30 |
+
|
31 |
+
configs = list()
|
32 |
+
for name in _URLS.keys():
|
33 |
+
config = datasets.BuilderConfig(name=name, version=VERSION, description=name)
|
34 |
+
configs.append(config)
|
35 |
+
|
36 |
+
BUILDER_CONFIGS = [
|
37 |
+
*configs
|
38 |
+
]
|
39 |
+
|
40 |
+
def _info(self):
|
41 |
+
features = datasets.Features({
|
42 |
+
"singer_name": datasets.Sequence(datasets.Value("string")),
|
43 |
+
"song_name": datasets.Value("string"),
|
44 |
+
"subtitle": datasets.Value("string"),
|
45 |
+
"album_name": datasets.Value("string"),
|
46 |
+
"singer_id": datasets.Sequence(datasets.Value("int32")),
|
47 |
+
"singer_mid": datasets.Sequence(datasets.Value("string")),
|
48 |
+
"song_time_public": datasets.Value("string"),
|
49 |
+
"song_type": datasets.Value("int32"),
|
50 |
+
"language": datasets.Value("int32"),
|
51 |
+
"song_id": datasets.Value("int32"),
|
52 |
+
"song_mid": datasets.Value("string"),
|
53 |
+
"song_url": datasets.Value("string"),
|
54 |
+
"hot_comments": datasets.Sequence(feature=datasets.Features({
|
55 |
+
"comment_name": datasets.Value("string"),
|
56 |
+
"comment_text": datasets.Value("string"),
|
57 |
+
})),
|
58 |
+
"lyric": datasets.Value("string"),
|
59 |
+
|
60 |
+
})
|
61 |
+
return datasets.DatasetInfo(
|
62 |
+
features=features,
|
63 |
+
supervised_keys=None,
|
64 |
+
homepage="",
|
65 |
+
license="",
|
66 |
+
citation=_CITATION,
|
67 |
+
)
|
68 |
+
|
69 |
+
def _split_generators(self, dl_manager):
|
70 |
+
"""Returns SplitGenerators."""
|
71 |
+
url = _URLS[self.config.name]
|
72 |
+
dl_path = dl_manager.download(url)
|
73 |
+
archive_path = dl_path
|
74 |
+
|
75 |
+
return [
|
76 |
+
datasets.SplitGenerator(
|
77 |
+
name=datasets.Split.TRAIN,
|
78 |
+
gen_kwargs={"archive_path": archive_path, "split": "train"},
|
79 |
+
),
|
80 |
+
]
|
81 |
+
|
82 |
+
def _generate_examples(self, archive_path, split):
|
83 |
+
"""Yields examples."""
|
84 |
+
archive_path = Path(archive_path)
|
85 |
+
|
86 |
+
idx = 0
|
87 |
+
|
88 |
+
with open(archive_path, "r", encoding="utf-8") as f:
|
89 |
+
for row in f:
|
90 |
+
sample = json.loads(row)
|
91 |
+
|
92 |
+
hot_comments = sample["hot_comments"]
|
93 |
+
if isinstance(hot_comments, str):
|
94 |
+
continue
|
95 |
+
|
96 |
+
yield idx, {
|
97 |
+
k: sample.get(k, None) for k in self._info().features.keys()
|
98 |
+
}
|
99 |
+
idx += 1
|
100 |
+
|
101 |
+
|
102 |
+
if __name__ == '__main__':
|
103 |
+
pass
|