Upload nedzhi.py
Browse files
nedzhi.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import textwrap
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
|
7 |
+
_CITATION = """\
|
8 |
+
@inproceedings{larson-etal-2019-evaluation,
|
9 |
+
title = "An Evaluation Dataset for Intent Classification and Out-of-Scope Prediction",
|
10 |
+
author = "Larson, Stefan and
|
11 |
+
Mahendran, Anish and
|
12 |
+
Peper, Joseph J. and
|
13 |
+
Clarke, Christopher and
|
14 |
+
Lee, Andrew and
|
15 |
+
Hill, Parker and
|
16 |
+
Kummerfeld, Jonathan K. and
|
17 |
+
Leach, Kevin and
|
18 |
+
Laurenzano, Michael A. and
|
19 |
+
Tang, Lingjia and
|
20 |
+
Mars, Jason",
|
21 |
+
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP)",
|
22 |
+
year = "2019",
|
23 |
+
url = "https://www.aclweb.org/anthology/D19-1131"
|
24 |
+
}
|
25 |
+
"""
|
26 |
+
|
27 |
+
_DESCRIPTION = """\
|
28 |
+
This dataset is for evaluating the performance of intent classification systems in the
|
29 |
+
presence of "out-of-scope" queries. By "out-of-scope", we mean queries that do not fall
|
30 |
+
into any of the system-supported intent classes. Most datasets include only data that is
|
31 |
+
"in-scope". Our dataset includes both in-scope and out-of-scope data. You might also know
|
32 |
+
the term "out-of-scope" by other terms, including "out-of-domain" or "out-of-distribution".
|
33 |
+
"""
|
34 |
+
|
35 |
+
_DESCRIPTIONS = {
|
36 |
+
"small": textwrap.dedent(
|
37 |
+
"""\
|
38 |
+
Small, in which there are only 50 training queries per each in-scope intent
|
39 |
+
"""
|
40 |
+
),
|
41 |
+
"imbalanced": textwrap.dedent(
|
42 |
+
"""\
|
43 |
+
Imbalanced, in which intents have either 25, 50, 75, or 100 training queries.
|
44 |
+
"""
|
45 |
+
),
|
46 |
+
"plus": textwrap.dedent(
|
47 |
+
"""\
|
48 |
+
OOS+, in which there are 250 out-of-scope training examples, rather than 100.
|
49 |
+
"""
|
50 |
+
),
|
51 |
+
}
|
52 |
+
|
53 |
+
_URL = "https://amazon-massive-nlu-dataset.s3.amazonaws.com/amazon-massive-dataset-1.0.tar.gz"
|
54 |
+
|
55 |
+
_DATA_URLS = {
|
56 |
+
"small": "https://amazon-massive-nlu-dataset.s3.amazonaws.com/amazon-massive-dataset-1.0.tar.gz",
|
57 |
+
"imbalanced": "https://amazon-massive-nlu-dataset.s3.amazonaws.com/amazon-massive-dataset-1.0.tar.gz",
|
58 |
+
"plus": "https://amazon-massive-nlu-dataset.s3.amazonaws.com/amazon-massive-dataset-1.0.tar.gz",
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
class ClincConfig(datasets.BuilderConfig):
|
63 |
+
|
64 |
+
"""BuilderConfig for CLINC150"""
|
65 |
+
|
66 |
+
def __init__(self, description, data_url, citation, url, **kwrags):
|
67 |
+
"""
|
68 |
+
Args:
|
69 |
+
description: `string`, brief description of the dataset
|
70 |
+
data_url: `dictionary`, dict with url for each split of data.
|
71 |
+
citation: `string`, citation for the dataset.
|
72 |
+
url: `string`, url for information about the dataset.
|
73 |
+
**kwrags: keyword arguments frowarded to super
|
74 |
+
"""
|
75 |
+
super(ClincConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwrags)
|
76 |
+
self.description = description
|
77 |
+
self.data_url = data_url
|
78 |
+
self.citation = citation
|
79 |
+
self.url = url
|
80 |
+
|
81 |
+
|
82 |
+
class ClincOos(datasets.GeneratorBasedBuilder):
|
83 |
+
BUILDER_CONFIGS = [
|
84 |
+
ClincConfig(
|
85 |
+
name=name, description=_DESCRIPTIONS[name], data_url=_DATA_URLS[name], citation=_CITATION, url=_URL
|
86 |
+
)
|
87 |
+
for name in ["small", "imbalanced", "plus"]
|
88 |
+
]
|
89 |
+
|
90 |
+
def _info(self):
|
91 |
+
features = {}
|
92 |
+
features["text"] = datasets.Value("string")
|
93 |
+
labels_list = [
|
94 |
+
'audio_volume_other',
|
95 |
+
'play_music',
|
96 |
+
'iot_hue_lighton',
|
97 |
+
'general_greet',
|
98 |
+
'calendar_set',
|
99 |
+
'audio_volume_down',
|
100 |
+
'social_query', 'audio_volume_mute', 'iot_wemo_on', 'iot_hue_lightup', 'audio_volume_up', 'iot_coffee', 'takeaway_query', 'qa_maths', 'play_game', 'cooking_query', 'iot_hue_lightdim', 'iot_wemo_off', 'music_settings', 'weather_query', 'news_query', 'alarm_remove', 'social_post', 'recommendation_events', 'transport_taxi', 'takeaway_order', 'music_query', 'calendar_query', 'lists_query', 'qa_currency', 'recommendation_movies', 'general_joke', 'recommendation_locations', 'email_querycontact', 'lists_remove', 'play_audiobook', 'email_addcontact', 'lists_createoradd', 'play_radio', 'qa_stock', 'alarm_query', 'email_sendemail', 'general_quirky', 'music_likeness', 'cooking_recipe', 'email_query', 'datetime_query', 'transport_traffic', 'play_podcasts', 'iot_hue_lightchange', 'calendar_remove', 'transport_query', 'transport_ticket', 'qa_factoid', 'iot_cleaning', 'alarm_set', 'datetime_convert', 'iot_hue_lightoff', 'qa_definition', 'music_dislikeness',
|
101 |
+
]
|
102 |
+
features["intent"] = datasets.ClassLabel(names=labels_list)
|
103 |
+
|
104 |
+
return datasets.DatasetInfo(
|
105 |
+
description=_DESCRIPTION + "\n" + self.config.description,
|
106 |
+
features=datasets.Features(features),
|
107 |
+
homepage=self.config.url,
|
108 |
+
citation=_CITATION,
|
109 |
+
)
|
110 |
+
|
111 |
+
def _split_generators(self, dl_manager):
|
112 |
+
file_ = dl_manager.download_and_extract(self.config.data_url)
|
113 |
+
|
114 |
+
return [
|
115 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file_, "split": "train"}),
|
116 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": file_, "split": "val"}),
|
117 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": file_, "split": "test"}),
|
118 |
+
]
|
119 |
+
|
120 |
+
def _generate_examples(self, filepath, split):
|
121 |
+
with open(filepath, encoding="utf-8") as f:
|
122 |
+
j = json.load(f)
|
123 |
+
for id_, row in enumerate(j[split] + j["oos_" + split]):
|
124 |
+
yield id_, {"text": row[0], "intent": row[1]}
|