File size: 2,330 Bytes
d6a4b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24b91d8
d6a4b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2298a34
d6a4b35
 
 
 
 
 
 
 
 
 
 
 
382e21f
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
import os
import pandas as pd
import datasets

class sato(datasets.GeneratorBasedBuilder):
    """The sato dataset"""

    def _info(self):
        features = datasets.Features(
            {
                "table_id": datasets.Value("string"),
                "col_idx": datasets.Value("string"),
                "label": datasets.Value("string"),
                "label_id": datasets.Value("string"),
                "data": datasets.Value("string"),
            }
        )

        #  datasets.value -- single value
        #  datasets.features.Sequence -- list
        
        return datasets.DatasetInfo(
            features=features
        )

    def _split_generators(self, dl_manager):
        sato_data = "https://huggingface.co/datasets/shivangibithel/SATO/blob/main"

        train_file1 = "msato_cv_0.csv"
        train_file2 = "msato_cv_1.csv"
        train_file3 = "msato_cv_2.csv"
        dev_file = "msato_cv_3.csv"
        test_file = "msato_cv_4.csv"
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"main_filepath": os.path.join(sato_data, train_file1)},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"main_filepath": os.path.join(sato_data, test_file)},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"main_filepath": os.path.join(sato_data, dev_file)},
            ),
        ]

    def _generate_examples(self, main_filepath):
        df = pd.read_csv(main_filepath,  encoding="utf8", sep=",")
        for ind in df.index:
            table_id = df['table_id'][ind]
            col_idx = df['col_idx'][ind]
            label = df['class'][ind]
            label_id = df['class_id'][ind]
            data = df['data'][ind]
            yield ind, {
                    "table_id": table_id,
                    "col_idx":col_idx,
                    "label": label,
                    "label_id": label_id,
                    "data": data,
                }