leyzer-fedcsis-translated / leyzer-fedcsis-translated.py
cartesinus's picture
add custom loading script
b1cec41
# coding=utf-8
"""Leyzer"""
import json
import datasets
import pandas as pd
_DESCRIPTION = """\
Leyzer is a multilingual text corpus designed to study multilingual and cross-lingual natural language
understanding (NLU) models and the strategies of localization of virtual assistants. It consists of 20
domains across three languages: English, Spanish and Polish, with 186 intents and a wide range of
samples, ranging from 1 to 672 sentences per intent.
"""
_CITATION = """\
@inproceedings{sowanski2020leyzer,
title={Leyzer: A Dataset for Multilingual Virtual Assistants},
author={Sowa{\'n}ski, Marcin and Janicki, Artur},
booktitle={International Conference on Text, Speech, and Dialogue},
pages={477--486},
year={2020},
organization={Springer}
}
"""
_LICENSE = """\
"""
_URL = "https://github.com/cartesinus/leyzer/raw/0.2.0/corpora/0.2.0/leyzer-0.2.0-fedcsis_translated.tar.gz"
_LANGUAGES = ['pl-PL']
_DOMAINS = ['Airconditioner', 'Calendar', 'Console', 'Contacts', 'Email', 'Facebook', 'Fitbit',
'Gdrive', 'Instagram', 'News', 'Phone', 'Slack', 'Speaker', 'Spotify', 'Translate',
'Twitter', 'Weather', 'Websearch', 'Wikipedia', 'Yelp', 'Youtube']
_INTENTS = ["AddAlbumToPlaylist", "AddEventOnDateWithName", "AddEventWithName",
"AddSongToPlaylist", "AddSongToPlaylistWithName", "AddSongWithNameToPlaylistWithName",
"AddWeight", "CallContact", "CallEmergency", "CallNumber", "ChangeLanguageToLanguage",
"ChangeTemperature", "CheckCalendarEventName", "CheckCalendarOnDate", "CheckChannelHistory",
"CheckLastMessages", "CheckMessagesFromUser", "CheckMessagesInChannel",
"CheckUserStatus", "ConsoleCD", "ConsoleCP", "ConsoleEdit", "ConsoleLS",
"ConsoleMV", "ConsoleRM", "CreateContactWithNameAndWithNumberAndWithType",
"CreateFile", "CreateFileWithName", "CreatePlaylist", "CreatePlaylistWithName",
"DecreaseVolume", "DecreaseVolumeByPercent", "DetectLanguage", "DownloadAsPdf",
"EditContactWithName", "EditContactWithNumber", "EditNumberInContactWithName",
"EditNumberInContactWithNameToNumberAndToType", "FindChannelWithQuery",
"FindQuery", "FindQueryOnChannel", "FollowUser", "GetHumidity", "GetTemperature",
"GetTemperatureFromDevice", "GoToElementNumber", "IncreaseVolume",
"IncreaseVolumeByPercent", "MoonphaseInLocation", "MoonphaseInLocationOnDate",
"MuteOff", "MuteOn", "NextSong", "NextVideo", "NotifyOnEventInLocation",
"NotifyOnEventStart", "NotifyOnNewFromFollowing", "NotifyOnWeight", "NotifyWhenEventNameStart",
"NotifyWhenPortalUpdates", "NotifyWhenPortalUpdatesInSection", "NotNotifyOnEventInLocation",
"NotNotifyOnEventStart", "OpenCalendar", "OpenContacts", "OpenEmail", "OpenEngine",
"OpenFacebook", "OpenFileWithName", "OpenGdrive", "OpenInstagram", "OpenMyContact",
"OpenRestaurants", "OpenRestaurantsInLocation", "OpenSlack", "OpenSpotify",
"OpenTwitter", "OpenWeather", "OpenWikipedia", "OpenYT", "Pause",
"PlayAlbumOfTypeByArtist", "PlayPlaylist", "PlaySong", "PlaySongByArtist",
"PostPicture", "PostPictureWithCaption", "PostPictureWithUrl",
"PostPictureWithUrlAndWithCaption", "PostStatus", "PostWithLastPictureWithLocationAndWithHashtag",
"PostWithPicturesFromDateAndWithLocation", "PreviousSong", "RandomPage",
"RepeatOnOff", "ReplyToEmailFromAddress", "ScrollDown", "ScrollUp",
"SearchByCategory", "SearchByCategoryInLocation", "SearchByQuery",
"SearchByQueryInLocation", "SearchByRating", "SearchByRatingInLocation",
"SearchByReviewCount", "SearchByReviewCountInLocation", "SearchImagesOnEngine",
"SearchImagesWithTextOnEngine", "SearchImagesWithTextOnEngineWithWidthAndWithHeight",
"SearchImagesWithTextOnEngineWithWidthAndWithHeightAndWithCondition", "SearchInLocation", "SearchQuery",
"SearchRestaurant", "SearchText", "SearchTextOnEngine", "SeekByTime", "SendEmail",
"SendEmailToAddress", "SendEmailToAddressWithSubject", "SendEmailToAddressWithSubjectAndWithMessage",
"SendMessageToChannel", "SendMessageToUser", "SendPictureToChannel", "SendPictureToChannelWithCaption",
"SendPictureWithUrlToChannel", "SendSlackMessage", "SendTwitterMessage", "SetDefaultLanguage",
"SetDefaultLanguageToLanguage", "SetPurposeOnChannel", "SetStatusAway", "SetTemperatureBetweenValues",
"SetTemperatureOnDevice", "SetTemperatureToValue", "SetTemperatureToValueOnDevice", "SetTopicInChannel",
"ShareFileWithNameToAddress", "ShowAlbumWithName", "ShowBMI", "ShowChannelWithCategory",
"ShowChannelWithName", "ShowContactWithEmail", "ShowContactWithName", "ShowContactWithNumber",
"ShowContactWithNumberAndWithEmail", "ShowDanceability", "ShowEmailFromSender", "ShowEmailFromTime",
"ShowEmailWithLabel", "ShowEmailWithPriority", "ShowEmailWithSubject", "ShowFilesFromTime",
"ShowFilesWithSize", "ShowFilesWithStar", "ShowFilesWithType", "ShowLastNumberPictures",
"ShowNewestFiles", "ShowNews", "ShowNewsFromSection", "ShowOldestFiles", "ShowPictures",
"ShowPicturesFromDate", "ShowPicturesWithFilter", "ShowPicturesWithHashtag",
"ShowPicturesWithLocation", "ShowSMS", "ShowSteps", "ShowStepsOnDate", "ShowSubscribedChannels",
"ShowTwittsWithHashtag", "ShuffleOnOff", "SMSToContact", "SMSToContactWithMessage",
"SortAlphabetical", "SortReverseAlphabetical", "SunriseAndSunsetInLocation",
"SunriseAndSunsetInLocationAndOnDate", "SunriseInLocation", "SunsetInLocation",
"TakePicture", "TranslateText", "TranslateTextFromLanguage", "TranslateTextFromLanguageToLanguage",
"TranslateTextFromLanguageToLanguageWithEngine", "TranslateTextToLanguage",
"TranslateToLanguage", "TurnOff", "TurnOn", "TurnOnOrOff", "UnfollowUser",
"WeatherInLocation", "WeatherTomorrow", "WeatherTomorrowInLocation",
"NotifyOnNewOnChannel"
]
_LEVELS = ['L0TC', 'L1TC', 'L2TC', 'REPHRASE']
_VPS = ['verb_pattern_01', 'verb_pattern_02', 'verb_pattern_03', 'verb_pattern_04',
'verb_pattern_05', 'verb_pattern_06', 'verb_pattern_07', 'verb_pattern_08',
'verb_pattern_09', 'verb_pattern_10', 'verb_pattern_11', 'verb_pattern_12', 'verb_pattern_13']
class LeyzerConfig(datasets.BuilderConfig):
"""BuilderConfig for Leyzer."""
def __init__(self, dataset_version=None, *args, **kwargs):
"""BuilderConfig for Leyzer.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(LeyzerConfig, self).__init__(*args, **kwargs)
self.dataset_version = dataset_version if dataset_version else "1.0"
self.data_url = _URL
class Leyzer(datasets.GeneratorBasedBuilder):
"""Leyzer"""
# All individual locale datasets are served from the latest version.
BUILDER_CONFIGS = [
LeyzerConfig(
name = name,
dataset_version = '0.2.0',
version = datasets.Version("0.2.0"),
description = f"The Leyzer v0.2.0 corpora for {name}",
) for name in _LANGUAGES
]
# Version 1.0
BUILDER_CONFIGS.append(LeyzerConfig(
name = "all",
dataset_version = '0.2.0',
version = datasets.Version("0.2.0"),
description = f"The Leyzer v0.2.0 corpora for entire corpus",
)
)
DEFAULT_CONFIG_NAME = "all"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"id": datasets.Value("string"),
"locale": datasets.Value("string"),
"partition": datasets.Value("string"),
"domain": datasets.features.ClassLabel(names=_DOMAINS),
"intent": datasets.features.ClassLabel(names=_INTENTS),
"utterance": datasets.Value("string"),
"bio": datasets.Value("string"),
},
),
supervised_keys=None,
homepage="https://github.com/cartesinus/leyzer/",
citation=_CITATION,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
archive = dl_manager.download(self.config.data_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"files": dl_manager.iter_archive(archive),
"split": "train",
"lang": self.config.name,
}
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"files": dl_manager.iter_archive(archive),
"split": "valid",
"lang": self.config.name,
}
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"files": dl_manager.iter_archive(archive),
"split": "test",
"lang": self.config.name,
}
),
]
def _generate_examples(self, files, split, lang):
key_ = 0
if lang == "all":
lang = _LANGUAGES.copy()
else:
lang = [lang]
for path, f in files:
l = path.split("/")[-1].split(".")[0]
if not lang:
break
elif l in lang:
lang.remove(l)
else:
continue
# Read the file
lines = f.read().decode(encoding="utf-8").split("\n")
for line in lines:
if not line:
continue
data = json.loads(line)
if data["partition"] != split:
continue
yield key_, {
"id": data["id"],
"locale": data["locale"],
"partition": data["partition"],
"domain": data["domain"],
"intent": data["intent"],
"utterance": data["utterance"],
"bio": data["bio"],
}
key_ += 1