Datasets:

Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
sileod commited on
Commit
9312b35
·
1 Parent(s): d3ec3f6

Create mtop.py

Browse files
Files changed (1) hide show
  1. mtop.py +97 -0
mtop.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ domain in {'alarm',
3
+ 'calling',
4
+ 'event',
5
+ 'messaging',
6
+ 'music',
7
+ 'news',
8
+ 'people',
9
+ 'recipes',
10
+ 'reminder',
11
+ 'timer',
12
+ 'weather'}
13
+ """
14
+
15
+ _URL = "https://fb.me/mtop_dataset"
16
+
17
+ _CITATION = """@article{li2020mtop,
18
+ title={MTOP: A comprehensive multilingual task-oriented semantic parsing benchmark},
19
+ author={Li, Haoran and Arora, Abhinav and Chen, Shuohui and Gupta, Anchit and Gupta, Sonal and Mehdad, Yashar},
20
+ journal={arXiv preprint arXiv:2008.09335},
21
+ year={2020}
22
+ }"""
23
+
24
+ _DESCRIPTION = """ """
25
+
26
+
27
+
28
+ class MtopConfig(datasets.BuilderConfig):
29
+ """BuilderConfig for Mtop."""
30
+
31
+ def __init__(self, **kwargs):
32
+ """BuilderConfig for Mtop.
33
+
34
+ Args:
35
+ **kwargs: keyword arguments forwarded to super.
36
+ """
37
+ super(MtopConfig, self).__init__(**kwargs)
38
+
39
+
40
+ class Mtop(datasets.GeneratorBasedBuilder):
41
+
42
+ BUILDER_CONFIGS = [
43
+ MtopConfig(
44
+ name="mtop",
45
+ version=datasets.Version("1.0.0", ""),
46
+ description="Plain text",
47
+ ),
48
+ ]
49
+
50
+ def _info(self):
51
+ return datasets.DatasetInfo(
52
+ description=_DESCRIPTION,
53
+ features=datasets.Features(
54
+ {
55
+ "idx": datasets.Value("string"),
56
+ "intent": datasets.Value("string"),
57
+ "spans": datasets.Value("string"),
58
+ "question": datasets.Value("string"),
59
+ "domain": datasets.Value("string"),
60
+ "lang": datasets.Value("string"),
61
+ "logical_form": datasets.Value("string"),
62
+ "tokenized_question": datasets.Value("string"),
63
+ }
64
+ ),
65
+ # No default supervised_keys (as we have to pass both question
66
+ # and context as input).
67
+ supervised_keys=None,
68
+ homepage="",
69
+ citation=_CITATION,
70
+
71
+ )
72
+
73
+ def _split_generators(self, dl_manager):
74
+ filepath = dl_manager.download_and_extract(_URL)
75
+
76
+ return [
77
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": filepath,"split":"train"}),
78
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": filepath,"split":"eval"}),
79
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": filepath,"split":"test"}),
80
+ ]
81
+
82
+ def _generate_examples(self, filepath, split):
83
+ """This function returns the examples in the raw (text) form."""
84
+ key = 0
85
+ with open(f"{filepath}/mtop/en/{split}.txt", encoding="utf-8") as f:
86
+ for example in f:
87
+ example = example.split("\t")
88
+ dict_example = dict(idx=example[0],
89
+ intent=example[1],
90
+ spans=example[2],
91
+ question=example[3],
92
+ domain=example[4],
93
+ lang=example[5],
94
+ logical_form=example[6],
95
+ tokenized_question=example[7])
96
+ yield key, dict_example
97
+ key += 1