File size: 3,516 Bytes
b8d00f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import pandas as pd
import datasets

# Define the dataset
class MyCsvDataset(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features({
                "TrackName": datasets.Value("string"),
                "TrackID": datasets.Value("int32"),
                "SampleURL": datasets.Value("string"),
                "ReleaseYear": datasets.Value("int32"),
                "Genres": datasets.Value("string"),
                "danceability": datasets.Value("float32"),
                "energy": datasets.Value("float32"),
                "loudness": datasets.Value("float32"),
                "speechiness": datasets.Value("float32"),
                "acousticness": datasets.Value("float32"),
                "instrumentalness": datasets.Value("float32"),
                "liveness": datasets.Value("float32"),
                "valence": datasets.Value("float32"),
                "tempo": datasets.Value("float32"),
                "key": datasets.Value("int32"),
                "mode": datasets.Value("int32"),
                "duration_ms": datasets.Value("int32"),
                "Popularity": datasets.Value("int32"),
                "pNum": datasets.Value("int32"),
                "playlistID": datasets.Value("string"),
                "label": datasets.Value("string"),
                "userCat": datasets.Value("string"),
                "demoCat": datasets.Value("string"),
                "length": datasets.Value("int32"),
                "playlistTitle": datasets.Value("string"),
                "nFoll": datasets.Value("int32"),
                "nTracks": datasets.Value("int32"),
            })
        )

    def _split_generators(self, dl_manager):
        # Define the dataset splits
        data_dir = dl_manager.download_and_extract("path_to_your_data")
        csv_file = os.path.join(data_dir, "your_dataset.csv")

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"csv_file": csv_file},
            ),
        ]

    def _generate_examples(self, csv_file):
        # Yield examples from the CSV file
        df = pd.read_csv(csv_file)
        for idx, row in df.iterrows():
            yield idx, {
                "TrackName": row["TrackName"],
                "TrackID": row["TrackID"],
                "SampleURL": row["SampleURL"],
                "ReleaseYear": row["ReleaseYear"],
                "Genres": row["Genres"],
                "danceability": row["danceability"],
                "energy": row["energy"],
                "loudness": row["loudness"],
                "speechiness": row["speechiness"],
                "acousticness": row["acousticness"],
                "instrumentalness": row["instrumentalness"],
                "liveness": row["liveness"],
                "valence": row["valence"],
                "tempo": row["tempo"],
                "key": row["key"],
                "mode": row["mode"],
                "duration_ms": row["duration_ms"],
                "Popularity": row["Popularity"],
                "pNum": row["pNum"],
                "playlistID": row["playlistID"],
                "label": row["label"],
                "userCat": row["userCat"],
                "demoCat": row["demoCat"],
                "length": row["length"],
                "playlistTitle": row["playlistTitle"],
                "nFoll": row["nFoll"],
                "nTracks": row["nTracks"],
            }