File size: 2,184 Bytes
bbdafef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import datasets

_DESCRIPTION = "MTOP: Multilingual Task-Oriented Semantic Parsing"
_LANGUAGES = ["en", "de", "es", "fr", "hi", "th"]

URL = ""  # https://huggingface.co./datasets/mteb/mtop/resolve/main/"
_URLs = {
    split: {
        "train": URL + f"{split}/train.jsonl",
        "test": URL + f"{split}/test.jsonl",
        "validation": URL + f"{split}/validation.jsonl",
    }
    for split in _LANGUAGES
}


class MTOP(datasets.GeneratorBasedBuilder):
    """MTOP Dataset."""

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=name, description=f"This part of my dataset covers {name} part of MTOP Dataset.",)
        for name in _LANGUAGES
    ]
    
    DEFAULT_CONFIG_NAME = "en"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "id": datasets.Value("int64"),
                    "text": datasets.Value("string"),
                    "label": datasets.Value("int32"),
                    "label_text": datasets.Value("string"),
                }
            ),
            supervised_keys=None,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        my_urls = _URLs[self.config.name]
        data_dir = dl_manager.download_and_extract(my_urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"text_path": data_dir["train"]},
            ),
            datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"text_path": data_dir["validation"]},),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                # These kwargs will be passed to _generate_examples
                gen_kwargs={"text_path": data_dir["test"]},
            ),
        ]

    def _generate_examples(self, text_path):
        """Yields examples."""
        with open(text_path, encoding="utf-8") as f:
            texts = f.readlines()
        for i, text in enumerate(texts):
            yield i, json.loads(text)