File size: 2,154 Bytes
fe38569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

"""Chess studies and annotated games from the top lichess studies and from https://www.angelfire.com/games3/smartbridge/"""


import os
import pandas as pd

import datasets


_CITATION = """TO COME."""

_DESCRIPTION = """\
Chess studies and annotated games from the top lichess studies and from https://www.angelfire.com/games3/smartbridge/
This dataset consists of annotated chess games from several sources and aggregated into a single dataset. It is intended 
to train language models to generate chess games and studies.
"""

_HOMEPAGE = ""

_LICENSE = "CC0"

_URLS = {
    "lichess": "lichess_studies.csv",
    "others": "others.csv",
}


class ChessStudies(datasets.GeneratorBasedBuilder):

    VERSION = datasets.Version("1.0.0")


    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="lichess", version=VERSION, description="Top studies scrapped from the lichess website"),
        datasets.BuilderConfig(name="others", version=VERSION, description="Studies aggregated from other sources"),
    ]

    DEFAULT_CONFIG_NAME = "lichess"

    def _info(self):
        features = datasets.Features(
            {
                "text": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        urls = _URLS[self.config.name]
        data_dir = dl_manager.download(urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={
                    "filepath": os.path.join(data_dir),
                    "split": "train",
                },
            ),
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath, split):
        df = pd.read_csv(filepath)
        for i, row in df.iterrows():
            yield i, {
                "text": row['text'],
            }