Add dataset script
Browse files- dataset_script.py +84 -0
dataset_script.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pandas as pd
|
3 |
+
import datasets
|
4 |
+
|
5 |
+
# Define the dataset
|
6 |
+
class MyCsvDataset(datasets.GeneratorBasedBuilder):
|
7 |
+
def _info(self):
|
8 |
+
return datasets.DatasetInfo(
|
9 |
+
features=datasets.Features({
|
10 |
+
"TrackName": datasets.Value("string"),
|
11 |
+
"TrackID": datasets.Value("int32"),
|
12 |
+
"SampleURL": datasets.Value("string"),
|
13 |
+
"ReleaseYear": datasets.Value("int32"),
|
14 |
+
"Genres": datasets.Value("string"),
|
15 |
+
"danceability": datasets.Value("float32"),
|
16 |
+
"energy": datasets.Value("float32"),
|
17 |
+
"loudness": datasets.Value("float32"),
|
18 |
+
"speechiness": datasets.Value("float32"),
|
19 |
+
"acousticness": datasets.Value("float32"),
|
20 |
+
"instrumentalness": datasets.Value("float32"),
|
21 |
+
"liveness": datasets.Value("float32"),
|
22 |
+
"valence": datasets.Value("float32"),
|
23 |
+
"tempo": datasets.Value("float32"),
|
24 |
+
"key": datasets.Value("int32"),
|
25 |
+
"mode": datasets.Value("int32"),
|
26 |
+
"duration_ms": datasets.Value("int32"),
|
27 |
+
"Popularity": datasets.Value("int32"),
|
28 |
+
"pNum": datasets.Value("int32"),
|
29 |
+
"playlistID": datasets.Value("string"),
|
30 |
+
"label": datasets.Value("string"),
|
31 |
+
"userCat": datasets.Value("string"),
|
32 |
+
"demoCat": datasets.Value("string"),
|
33 |
+
"length": datasets.Value("int32"),
|
34 |
+
"playlistTitle": datasets.Value("string"),
|
35 |
+
"nFoll": datasets.Value("int32"),
|
36 |
+
"nTracks": datasets.Value("int32"),
|
37 |
+
})
|
38 |
+
)
|
39 |
+
|
40 |
+
def _split_generators(self, dl_manager):
|
41 |
+
# Define the dataset splits
|
42 |
+
data_dir = dl_manager.download_and_extract("path_to_your_data")
|
43 |
+
csv_file = os.path.join(data_dir, "your_dataset.csv")
|
44 |
+
|
45 |
+
return [
|
46 |
+
datasets.SplitGenerator(
|
47 |
+
name=datasets.Split.TRAIN,
|
48 |
+
gen_kwargs={"csv_file": csv_file},
|
49 |
+
),
|
50 |
+
]
|
51 |
+
|
52 |
+
def _generate_examples(self, csv_file):
|
53 |
+
# Yield examples from the CSV file
|
54 |
+
df = pd.read_csv(csv_file)
|
55 |
+
for idx, row in df.iterrows():
|
56 |
+
yield idx, {
|
57 |
+
"TrackName": row["TrackName"],
|
58 |
+
"TrackID": row["TrackID"],
|
59 |
+
"SampleURL": row["SampleURL"],
|
60 |
+
"ReleaseYear": row["ReleaseYear"],
|
61 |
+
"Genres": row["Genres"],
|
62 |
+
"danceability": row["danceability"],
|
63 |
+
"energy": row["energy"],
|
64 |
+
"loudness": row["loudness"],
|
65 |
+
"speechiness": row["speechiness"],
|
66 |
+
"acousticness": row["acousticness"],
|
67 |
+
"instrumentalness": row["instrumentalness"],
|
68 |
+
"liveness": row["liveness"],
|
69 |
+
"valence": row["valence"],
|
70 |
+
"tempo": row["tempo"],
|
71 |
+
"key": row["key"],
|
72 |
+
"mode": row["mode"],
|
73 |
+
"duration_ms": row["duration_ms"],
|
74 |
+
"Popularity": row["Popularity"],
|
75 |
+
"pNum": row["pNum"],
|
76 |
+
"playlistID": row["playlistID"],
|
77 |
+
"label": row["label"],
|
78 |
+
"userCat": row["userCat"],
|
79 |
+
"demoCat": row["demoCat"],
|
80 |
+
"length": row["length"],
|
81 |
+
"playlistTitle": row["playlistTitle"],
|
82 |
+
"nFoll": row["nFoll"],
|
83 |
+
"nTracks": row["nTracks"],
|
84 |
+
}
|