File size: 4,033 Bytes
ded984d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5971f4a
ded984d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""Chess"""

from typing import List

import datasets

import pandas


VERSION = datasets.Version("1.0.0")
_BASE_FEATURE_NAMES = [
    "bkblk",
	"bknwy",
	"bkon8",
	"bkona",
	"bkspr",
	"bkxbq",
	"bkxcr",
	"bkxwp",
	"blxwp",
	"bxqsq",
	"cntxt",
	"dsopp",
	"dwipd",
	"hdchk",
	"katri",
	"mulch",
	"qxmsq",
	"r2ar8",
	"reskd",
	"reskr",
	"rimmx",
	"rkxwp",
	"rxmsq",
	"simpl",
	"skach",
	"skewr",
	"skrxp",
	"spcop",
	"stlmt",
	"thrsk",
	"wkcti",
	"wkna8",
	"wknck",
	"wkovl",
	"wkpos",
	"white_wins"
]

DESCRIPTION = "Chess dataset from the UCI ML repository."
_HOMEPAGE = "https://archive.ics.uci.edu/ml/datasets/Chess"
_URLS = ("https://huggingface.co/datasets/mstz/chess/raw/chess.csv")
_CITATION = """
@misc{misc_chess_(king-rook_vs._king-pawn)_22,
  title        = {{Chess (King-Rook vs. King-Pawn)}},
  year         = {1989},
  howpublished = {UCI Machine Learning Repository},
  note         = {{DOI}: \\url{10.24432/C5DK5C}}
}"""

# Dataset info
urls_per_split = {
    "train": "https://huggingface.co/datasets/mstz/chess/raw/main/kr-vs-kp.data"
}
features_types_per_config = {
    "chess": {
        "bkblk": datasets.Value("string"),
        "bknwy": datasets.Value("string"),
        "bkon8": datasets.Value("string"),
        "bkona": datasets.Value("string"),
        "bkspr": datasets.Value("string"),
        "bkxbq": datasets.Value("string"),
        "bkxcr": datasets.Value("string"),
        "bkxwp": datasets.Value("string"),
        "blxwp": datasets.Value("string"),
        "bxqsq": datasets.Value("string"),
        "cntxt": datasets.Value("string"),
        "dsopp": datasets.Value("string"),
        "dwipd": datasets.Value("string"),
        "hdchk": datasets.Value("string"),
        "katri": datasets.Value("string"),
        "mulch": datasets.Value("string"),
        "qxmsq": datasets.Value("string"),
        "r2ar8": datasets.Value("string"),
        "reskd": datasets.Value("string"),
        "reskr": datasets.Value("string"),
        "rimmx": datasets.Value("string"),
        "rkxwp": datasets.Value("string"),
        "rxmsq": datasets.Value("string"),
        "simpl": datasets.Value("string"),
        "skach": datasets.Value("string"),
        "skewr": datasets.Value("string"),
        "skrxp": datasets.Value("string"),
        "spcop": datasets.Value("string"),
        "stlmt": datasets.Value("string"),
        "thrsk": datasets.Value("string"),
        "wkcti": datasets.Value("string"),
        "wkna8": datasets.Value("string"),
        "wknck": datasets.Value("string"),
        "wkovl": datasets.Value("string"),
        "wkpos": datasets.Value("string"),
        "wtoeg": datasets.Value("string"),
        "white_wins": datasets.ClassLabel(num_classes=2, names=("no", "yes"))
    }
}
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config}


class ChessConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super(ChessConfig, self).__init__(version=VERSION, **kwargs)
        self.features = features_per_config[kwargs["name"]]


class Chess(datasets.GeneratorBasedBuilder):
    # dataset versions
    DEFAULT_CONFIG = "chess"
    BUILDER_CONFIGS = [
        ChessConfig(name="chess",
                    description="Chess for binary classification.")
    ]


    def _info(self):
        info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE,
                                    features=features_per_config[self.config.name])

        return info
    
    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        downloads = dl_manager.download_and_extract(urls_per_split)

        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]})
        ]
    
    def _generate_examples(self, filepath: str):
        data = pandas.read_csv(filepath)

        for row_id, row in data.iterrows():
            data_row = dict(row)

            yield row_id, data_row