|
""" Dataloader for Caissabase's chess games. """ |
|
|
|
import os |
|
import csv |
|
import json |
|
import datasets |
|
|
|
|
|
FILEPATH = "https://huggingface.co/datasets/mapama247/chess_games_caissabase/resolve/main/chess_games_caissabase.jsonl" |
|
|
|
class ChessGamesCaissabase(datasets.GeneratorBasedBuilder): |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"moves": datasets.Value("string"), |
|
"length": datasets.Value("int32"), |
|
"result": datasets.Value("string"), |
|
"checkmate": datasets.Value("bool"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo(features=features) |
|
|
|
def _split_generators(self, dl_manager): |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": FILEPATH, |
|
"split": "train", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
yield key, { |
|
"moves": data["moves"], |
|
"length": data["length"], |
|
"result": data["result"], |
|
"checkmate": data["checkmate"], |
|
} |
|
|