| |
| '''DiaBLA: "Dialogue Bilingue" Bilingual dialogue dataset''' |
|
|
| import json |
| import datasets |
|
|
| logger = datasets.logging.get_logger(__name__) |
|
|
| _CITATION = '''\ |
| @article{bawden_DiaBLa:-A-Corpus-of_2021, |
| author = {Bawden, Rachel and Bilinski, Eric and Lavergne, Thomas and Rosset, Sophie}, |
| doi = {10.1007/s10579-020-09514-4}, |
| title = {DiaBLa: A Corpus of Bilingual Spontaneous Written Dialogues for Machine Translation}, |
| year = {2021}, |
| journal = {Language Resources and Evaluation}, |
| publisher = {Springer Verlag}, |
| volume = {55}, |
| pages = {635--660}, |
| url = {https://hal.inria.fr/hal-03021633}, |
| pdf = {https://hal.inria.fr/hal-03021633/file/diabla-lre-personal-formatting.pdf}, |
| } |
| ''' |
|
|
| _DESCRIPTION = '''\ |
| English-French parallel dataset for the evaluation of \ |
| Machine Translation (MT) for informal, written bilingual dialogue. |
| ''' |
| |
| _URLS = { |
| 'test': 'DiaBLa.json', |
| } |
|
|
|
|
| class DiablaConfig(datasets.BuilderConfig): |
| '''BuilderConfig for DiaBLa.''' |
|
|
| def __init__(self, **kwargs): |
| """BuilderConfig for DiaBLa. |
| |
| Args: |
| **kwargs: keyword arguments forwarded to super. |
| """ |
| super(DiablaConfig, self).__init__(**kwargs) |
|
|
|
|
| class Diabla(datasets.GeneratorBasedBuilder): |
| '''DiaBLa: English-French parallel dataset of bilingual dialogue''' |
|
|
| BUILDER_CONFIGS = [ |
| DiablaConfig( |
| name='plain_text', |
| version=datasets.Version('1.0.0', ''), |
| description='Plain text', |
| ), |
| ] |
|
|
| |
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features( |
| { |
| 'id': datasets.Value('string'), |
| 'orig': datasets.Value('string'), |
| 'norm': datasets.Value('string'), |
| 'mt': datasets.Value('string'), |
| 'ref': datasets.Value('string'), |
| 'utterance_meta': { |
| 'eval_judgment': datasets.Value("string"), |
| 'eval_verbatim': datasets.Value('string'), |
| 'eval_problems': [ |
| datasets.Value("string") |
| ], |
| 'lang': datasets.Value("string") |
| }, |
| 'dialogue_meta': { |
| 'start_time': datasets.Value('string'), |
| 'end_time' : datasets.Value('string'), |
| 'translation_model': datasets.Value('string'), |
| 'final_evaluation_user1': { |
| 'style': datasets.Value("string"), |
| 'coherence': datasets.Value("string"), |
| 'grammaticality': datasets.Value("string"), |
| 'meaning': datasets.Value("string"), |
| 'word_choice': datasets.Value("string"), |
| }, |
| 'final_evaluation_user2': { |
| 'style': datasets.Value("string"), |
| 'coherence': datasets.Value("string"), |
| 'grammaticality': datasets.Value("string"), |
| 'meaning': datasets.Value("string"), |
| 'word_choice': datasets.Value("string"), |
| }, |
| 'scenario': [[ |
| datasets.Value("string") |
| ]], |
| 'user1': { |
| 'role_num': datasets.Value('int64'), |
| 'role':[ |
| datasets.Value('string') |
| ], |
| 'initiated_dialogue': datasets.Value('bool'), |
| 'turn_number': datasets.Value('int64'), |
| 'lang': datasets.Value("string"), |
| }, |
| 'user2':{ |
| 'role_num': datasets.Value('int64'), |
| 'role':[ |
| datasets.Value('string') |
| ], |
| 'initiated_dialogue': datasets.Value('bool'), |
| 'turn_number': datasets.Value('int64'), |
| 'lang': datasets.Value("string"), |
| } |
| }, |
| 'dialogue_history': [ |
| { |
| 'id': datasets.Value('string'), |
| 'orig': datasets.Value('string'), |
| 'norm': datasets.Value('string'), |
| 'mt': datasets.Value('string'), |
| 'ref': datasets.Value('string'), |
| 'utterance_meta': { |
| 'eval_judgment': datasets.Value("string"), |
| 'eval_verbatim': datasets.Value("string"), |
| 'eval_problems': [ |
| datasets.Value("string") |
| ], |
| 'lang': datasets.Value("string"), |
| } |
| } |
| ] |
| } |
| ), |
| supervised_keys=None, |
| homepage='https://github.com/rbawden/DiaBLa-dataset', |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
| return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={'filepath': downloaded_files['test']})] |
|
|
| def _generate_examples(self, filepath): |
| '''This function returns the examples in the raw (text) form.''' |
| logger.info("generating examples from = %s", filepath) |
| key = 0 |
| with open(filepath, encoding="utf-8") as f: |
| diabla = json.load(f) |
| for dialogue_name in sorted(diabla['dialogues']): |
| dialogue_history = [] |
| dialogue = diabla['dialogues'][dialogue_name] |
| |
| dialogue_info_keys = ['start_time', 'end_time', 'scenario', |
| 'user1', 'user2', 'translation_model', |
| 'final_evaluation_user1', 'final_evaluation_user2'] |
| |
| for user in 'user1', 'user2': |
| dialogue[user]['role_num'] = dialogue[user].get('role_num', dialogue[user].get('rolenum', '')) |
| for info_to_remove in ['eval-stage', 'useragent', 'rolenum']: |
| if info_to_remove in dialogue[user]: |
| del dialogue[user][info_to_remove] |
| |
| |
| dialogue_info = {k: dialogue[k] for k in dialogue_info_keys} |
| if dialogue_info['end_time'] is None: |
| dialogue_info['end_time'] = '' |
| for final_eval in 'final_evaluation_user1', 'final_evaluation_user2': |
| |
| if dialogue_info[final_eval] == {}: |
| dialogue_info[final_eval] = {'grammaticality': '', 'meaning': '', |
| 'coherence': '', 'style': '', 'word_choice': ''} |
| |
| for info_to_remove in ['interface','verbatim_quality', |
| 'particular_problems', 'tech', |
| 'would_use', 'timestamp', 'technical_issue']: |
| if info_to_remove in dialogue_info[final_eval]: |
| del dialogue_info[final_eval][info_to_remove] |
| |
| |
| for utterance_id in dialogue['utterances']: |
| utterance = dialogue['utterances'][utterance_id] |
| |
| utterance_info_keys = ['judgment', 'verbatim', 'problems'] |
| utterance_info = {'eval_' + k: utterance['eval'][k] for k in utterance_info_keys} |
| if utterance_info['eval_judgment'] is None: |
| utterance_info['eval_judgment'] = '' |
| utterance_info['lang'] = utterance['language'] |
| |
| original_text = utterance['original_text'] |
| mt_text = utterance['postprocessed_text'] |
| reference_text = utterance['reference_translation'] |
| normalised_text = utterance['normalised_version'] |
| id_ = dialogue_name + '_' + utterance_id |
| utterance_instance = { |
| 'orig': original_text, |
| 'norm': normalised_text, |
| 'mt': mt_text, |
| 'id': id_, |
| 'ref': reference_text.replace('’', "'").replace('…', '...'), |
| 'utterance_meta': utterance_info |
| } |
| |
| |
| minimal_utterance = utterance_instance.copy() |
| utterance_instance['dialogue_meta'] = dialogue_info |
| utterance_instance['dialogue_history'] = dialogue_history.copy() |
| dialogue_history.append(minimal_utterance) |
| yield id_, utterance_instance |
|
|