File size: 1,808 Bytes
e3a713a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97280cf
 
e3a713a
acc8baa
 
 
 
 
e3a713a
 
 
 
acc8baa
e3a713a
 
 
 
 
acc8baa
e3a713a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 datasets
from sklearn.preprocessing import MinMaxScaler, LabelEncoder, StandardScaler
import numpy as np


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {A great new dataset},
author={huggingface, Inc.
},
year={2020}
}
"""

class Reuters10K(datasets.GeneratorBasedBuilder):
    """TODO: Short description of my dataset."""

    VERSION = datasets.Version("0.0.1")

    def _info(self):
        return datasets.DatasetInfo(
            description="Reuters10K dataset",
            version=Reuters10K.VERSION,
        )

    def _split_generators(self, dl_manager):
        train_url = "train.npy"
        test_url = "test.npy"

        downloaded_files = dl_manager.download_and_extract({
            "train": train_url, 
            "test": test_url
        })

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": downloaded_files["train"]
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": downloaded_files["test"]
                },
            )
        ]

    def _generate_examples(self, filepath):
        """Yields examples."""
        train_dataset = np.load(filepath, allow_pickle=True)

        X_train = train_dataset.item()['data']
        Y_train = train_dataset.item()['label']

        scaler = MinMaxScaler()
        X_train = scaler.fit_transform(X_train)

        # yield "key", {"text": text, "label": label}
        for i, (x, y) in enumerate(zip(X_train, Y_train)):
            yield i, {"features": x, "label": y}