import json import os import datasets _OPEN_SLU_CITATION = """\ xxx""" _OPEN_SLU_DESCRIPTION = """\ xxx""" _ATIS_CITATION = """\ @inproceedings{hemphill1990atis, title = "The {ATIS} Spoken Language Systems Pilot Corpus", author = "Hemphill, Charles T. and Godfrey, John J. and Doddington, George R.", booktitle = "Speech and Natural Language: Proceedings of a Workshop Held at Hidden Valley, {P}ennsylvania, June 24-27,1990", year = "1990", url = "https://aclanthology.org/H90-1021", } """ _ATIS_DESCRIPTION = """\ A widely used SLU corpus for single-intent SLU. """ _SNIPS_CITATION = """\ @article{coucke2018snips, title={Snips voice platform: an embedded spoken language understanding system for private-by-design voice interfaces}, author={Coucke, Alice and Saade, Alaa and Ball, Adrien and Bluche, Th{\'e}odore and Caulier, Alexandre and Leroy, David and Doumouro, Cl{\'e}ment and Giss\textsf{el}brecht, Thibault and Caltagirone, Francesco and Lavril, Thibaut and others}, journal={arXiv preprint arXiv:1805.10190}, year={2018} } """ _SNIPS_DESCRIPTION = """\ A widely used SLU corpus for single-intent SLU. """ _MIX_ATIS_CITATION = """\ @inproceedings{qin2020agif, title = "{AGIF}: An Adaptive Graph-Interactive Framework for Joint Multiple Intent Detection and Slot Filling", author = "Qin, Libo and Xu, Xiao and Che, Wanxiang and Liu, Ting", booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020", month = nov, year = "2020", address = "Online", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2020.findings-emnlp.163", doi = "10.18653/v1/2020.findings-emnlp.163", pages = "1807--1816", abstract = "In real-world scenarios, users usually have multiple intents in the same utterance. Unfortunately, most spoken language understanding (SLU) models either mainly focused on the single intent scenario, or simply incorporated an overall intent context vector for all tokens, ignoring the fine-grained multiple intents information integration for token-level slot prediction. In this paper, we propose an Adaptive Graph-Interactive Framework (AGIF) for joint multiple intent detection and slot filling, where we introduce an intent-slot graph interaction layer to model the strong correlation between the slot and intents. Such an interaction layer is applied to each token adaptively, which has the advantage to automatically extract the relevant intents information, making a fine-grained intent information integration for the token-level slot prediction. Experimental results on three multi-intent datasets show that our framework obtains substantial improvement and achieves the state-of-the-art performance. In addition, our framework achieves new state-of-the-art performance on two single-intent datasets.", } """ _MIX_ATIS_DESCRIPTION = """\ A widely used SLU corpus for multi-intent SLU. """ _MIX_SNIPS_CITATION = """\ @inproceedings{qin2020agif, title = "{AGIF}: An Adaptive Graph-Interactive Framework for Joint Multiple Intent Detection and Slot Filling", author = "Qin, Libo and Xu, Xiao and Che, Wanxiang and Liu, Ting", booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2020", month = nov, year = "2020", address = "Online", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2020.findings-emnlp.163", doi = "10.18653/v1/2020.findings-emnlp.163", pages = "1807--1816", abstract = "In real-world scenarios, users usually have multiple intents in the same utterance. Unfortunately, most spoken language understanding (SLU) models either mainly focused on the single intent scenario, or simply incorporated an overall intent context vector for all tokens, ignoring the fine-grained multiple intents information integration for token-level slot prediction. In this paper, we propose an Adaptive Graph-Interactive Framework (AGIF) for joint multiple intent detection and slot filling, where we introduce an intent-slot graph interaction layer to model the strong correlation between the slot and intents. Such an interaction layer is applied to each token adaptively, which has the advantage to automatically extract the relevant intents information, making a fine-grained intent information integration for the token-level slot prediction. Experimental results on three multi-intent datasets show that our framework obtains substantial improvement and achieves the state-of-the-art performance. In addition, our framework achieves new state-of-the-art performance on two single-intent datasets.", } """ _MIX_SNIPS_DESCRIPTION = """\ A widely used SLU corpus for multi-intent SLU. """ class OpenSLUConfig(datasets.BuilderConfig): """BuilderConfig for OpenSLU.""" def __init__(self, features, data_url, citation, url, intent_label_classes=None, slot_label_classes=None, **kwargs): """BuilderConfig for OpenSLU. Args: features: `list[string]`, list of the features that will appear in the feature dict. Should not include "label". data_url: `string`, url to download the zip file from. citation: `string`, citation for the data set. url: `string`, url for information about the data set. intent_label_classes: `list[string]`, the list of classes for the intent label slot_label_classes: `list[string]`, the list of classes for the slot label **kwargs: keyword arguments forwarded to super. """ # Version history: # 0.0.1: Initial version. super(OpenSLUConfig, self).__init__(version=datasets.Version("0.0.1"), **kwargs) self.features = features self.intent_label_classes = intent_label_classes self.slot_label_classes = slot_label_classes self.data_url = data_url self.citation = citation self.url = url class OpenSLU(datasets.GeneratorBasedBuilder): """The SuperGLUE benchmark.""" BUILDER_CONFIGS = [ OpenSLUConfig( name="atis", description=_ATIS_DESCRIPTION, features=["text"], data_url="https://huggingface.co/datasets/LightChen2333/OpenSLU/resolve/main/atis.tar.gz", citation=_ATIS_CITATION, url="https://aclanthology.org/H90-1021", ), OpenSLUConfig( name="snips", description=_SNIPS_DESCRIPTION, features=["text"], data_url="https://huggingface.co/datasets/LightChen2333/OpenSLU/resolve/main/snips.tar.gz", citation=_SNIPS_CITATION, url="https://arxiv.org/abs/1805.10190", ), OpenSLUConfig( name="mix-atis", description=_MIX_ATIS_DESCRIPTION, features=["text"], data_url="https://huggingface.co/datasets/LightChen2333/OpenSLU/resolve/main/mix-atis.tar.gz", citation=_MIX_ATIS_CITATION, url="https://aclanthology.org/2020.findings-emnlp.163", ), OpenSLUConfig( name="mix-snips", description=_MIX_SNIPS_DESCRIPTION, features=["text"], data_url="https://huggingface.co/datasets/LightChen2333/OpenSLU/resolve/main/mix-snips.tar.gz", citation=_MIX_SNIPS_CITATION, url="https://aclanthology.org/2020.findings-emnlp.163", ), ] def _info(self): features = {feature: datasets.Sequence(datasets.Value("string")) for feature in self.config.features} features["slot"] = datasets.Sequence(datasets.Value("string")) features["intent"] = datasets.Value("string") return datasets.DatasetInfo( description=_OPEN_SLU_DESCRIPTION + self.config.description, features=datasets.Features(features), homepage=self.config.url, citation=self.config.citation + "\n" + _OPEN_SLU_CITATION, ) def _split_generators(self, dl_manager): print(self.config.data_url) dl_dir = dl_manager.download_and_extract(self.config.data_url) or "" task_name = _get_task_name_from_data_url(self.config.data_url) print(dl_dir) print(task_name) dl_dir = os.path.join(dl_dir, task_name) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data_file": os.path.join(dl_dir, "train.jsonl"), "split": datasets.Split.TRAIN, }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "data_file": os.path.join(dl_dir, "dev.jsonl"), "split": datasets.Split.VALIDATION, }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "data_file": os.path.join(dl_dir, "test.jsonl"), "split": datasets.Split.TEST, }, ), ] def _generate_examples(self, data_file, split): with open(data_file, encoding="utf-8") as f: for index, line in enumerate(f): row = json.loads(line) yield index, row def _cast_label(label): """Converts the label into the appropriate string version.""" if isinstance(label, str): return label elif isinstance(label, bool): return "True" if label else "False" elif isinstance(label, int): assert label in (0, 1) return str(label) else: raise ValueError("Invalid label format.") def _get_record_entities(passage): """Returns the unique set of entities.""" text = passage["text"] entity_spans = list() for entity in passage["entities"]: entity_text = text[entity["start"]: entity["end"] + 1] entity_spans.append({"text": entity_text, "start": entity["start"], "end": entity["end"] + 1}) entity_spans = sorted(entity_spans, key=lambda e: e["start"]) # sort by start index entity_texts = set(e["text"] for e in entity_spans) # for backward compatability return entity_texts, entity_spans def _get_record_answers(qa): """Returns the unique set of answers.""" if "answers" not in qa: return [] answers = set() for answer in qa["answers"]: answers.add(answer["text"]) return sorted(answers) def _get_task_name_from_data_url(data_url): return data_url.split("/")[-1].split(".")[0]