File size: 11,389 Bytes
3d81c4a
 
 
 
 
a2bd85f
3d81c4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d13342
0abbaee
2d13342
3d81c4a
 
 
 
 
 
b05395d
3d81c4a
 
 
 
c387054
3d81c4a
 
 
 
 
 
b05395d
3d4cc61
8236ab8
3d4cc61
3d81c4a
 
 
b05395d
3d81c4a
 
 
 
 
3d4cc61
 
 
 
 
d095de9
3d81c4a
8295f13
8236ab8
8295f13
d095de9
2632e46
d095de9
b1ec1ea
dff3b67
 
 
 
 
3d4cc61
 
 
82a987c
 
489bc09
 
 
 
 
3d4cc61
 
 
 
489bc09
 
 
 
 
3d4cc61
 
dff3b67
 
1455d68
 
 
dff3b67
ca3d393
dff3b67
 
3d4cc61
 
 
 
 
dff3b67
ca3d393
dff3b67
 
3d4cc61
 
 
 
 
dff3b67
d095de9
3d81c4a
 
dff3b67
 
0225b93
dff3b67
3d4cc61
 
 
 
 
0225b93
 
 
 
 
 
 
 
 
 
 
 
 
 
dff3b67
 
3d81c4a
 
dff3b67
3d81c4a
97fadc5
3d81c4a
 
 
 
 
 
2d13342
 
3d81c4a
8236ab8
3d81c4a
 
 
 
 
 
 
 
 
 
 
 
 
 
7e539c7
0140790
0278bca
0140790
3d81c4a
67aa832
2c343af
3d4cc61
 
 
 
 
 
3d81c4a
 
b671eb0
3d81c4a
7e539c7
3d81c4a
67aa832
 
f05adf8
3d81c4a
 
 
 
 
 
 
d095de9
 
 
3d81c4a
d095de9
 
3d81c4a
3d4cc61
f752342
3d81c4a
d2f34be
f752342
3d81c4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# coding=utf-8
'''DiaBLA: Dialogue Bilingue datset'''

import json
import datasets
from datasets.features import ClassLabel


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',
        ),
    ]

    #TODO
    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': datasets.features.Sequence(
                        {
                            'eval-judgment': ClassLabel(num_classes=3, names=['poor', 'medium', 'perfect']),
                            'eval-verbatim': datasets.Value('string'),
                            'eval-problems': datasets.features.Sequence(
                                [
                                  ClassLabel(num_classes=5, names=['coherence', 'grammar', 'meaning', 'word choice', 'style'])
                                ]
                              ),
                             'lang': ClassLabel(num_classes=2, names=['en', 'fr']),
                        }
                    ),
                    'dialogue_meta': datasets.features.Sequence(
                        {
                            'start_time': datasets.Value('string'), 
                            'end_time' : datasets.Value('string'),
                            'translation_model': datasets.Value('string'),
                            'final_evaluation_user1': datasets.features.Sequence(
                                {
                                    'style': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'coherence': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'grammaticality': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'meaning': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'word_choice': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent'])
                                 }
                             ),
                            'final_evaluation_user2': datasets.features.Sequence(
                                {
                                    'style': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'coherence': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'grammaticality': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'meaning': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent']),
                                    'word_choice': ClassLabel(num_classes=4, names=['poor', 'average', 'good', 'excellent'])
                                 }
                             ),
                            'scenario': datasets.features.Sequence(
                                [
                                  [
                                     datasets.Value("string")
                                  ]                                                                            
                                ]
                            ),
                            'user1': datasets.features.Sequence(
                                {
                                   'rolenum': datasets.Value('int64'),
                                   'role': datasets.Value('string'),
                                   'initiated_dialogue': datasets.Value('bool'),
                                   'turn_number': datasets.Value('int64'),
                                   'lang': datasets.Value('string'),
                                }
                            ),
                            'user2': datasets.features.Sequence(
                                {
                                   'rolenum': datasets.Value('int64'),
                                   'role': datasets.Value('string'),
                                   'initiated_dialogue': datasets.Value('bool'),
                                   'turn_number': datasets.Value('int64'),
                                   'lang': datasets.Value('string'),
                                }
                            )
                        }
                    ),
                    'dialogue_history': datasets.features.Sequence(
                        [
                            datasets.features.Sequence(
                                {
                                    'id': datasets.Value('string'),
                                    'orig': datasets.Value('string'),
                                    'norm': datasets.Value('string'),
                                    'mt': datasets.Value('string'),
                                    'ref': datasets.Value('string'),
                                    'utterance_meta': datasets.features.Sequence(
                                        {
                                            'judgment': ClassLabel(num_classes=3, names=['poor', 'medium', 'perfect']),
                                             'verbatim': datasets.Value("string"),
                                             'problems': datasets.features.Sequence(
                                                 [
                                                     ClassLabel(num_classes=5, 
                                                                names=['coherence', 'grammar', 'meaning', 'word choice', 'style'])
                                                 ]
                                              ),
                                             'lang': ClassLabel(num_classes=2, names=['en', 'fr']),
                                        }
                                    ),
                             }),
                        ]
                    )
                }
            ),
            # TODO?
            supervised_keys=None,
            homepage='https://github.com/rbawden/DiaBLa-dataset',
            citation=_CITATION,
            task_templates=[
                # TODO
            ],
        )

    def _split_generators(self, dl_manager):
        downloaded_files = dl_manager.download_and_extract(_URLS)

        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, 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 = [] # to store past utterances
                dialogue = diabla['dialogues'][dialogue_name]
                # Meta-information attached to the dialogue
                dialogue_info_keys = ['start_time', 'end_time', 'scenario',
                                      'user1', 'user2', 'translation_model',
                                      'final_evaluation_user1', 'final_evaluation_user2']
                for info_to_remove in ['eval-stage', 'useragent']:
                    for user in 'user1', 'user2':
                        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 info_to_remove in ['interface','verbatim_quality', 
                                       'particular_problems', 'tech', 
                                       'would_use', 'timestamp', 'technical_issue']:
                    del dialogue_info['final_evaluation_user1'][info_to_remove]
                    del dialogue_info['final_evaluation_user2'][info_to_remove]
                    
                # Main data: the utterances
                for utterance_id in dialogue['utterances']:
                    utterance = dialogue['utterances'][utterance_id]
                    # Meta-information attached to the utterance
                    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']
                    # Utterance text
                    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,
                        'utterance_meta': utterance_info
                    }
                    
                    # add to history (without dialogue info and history)
                    dialogue_history.append(utterance_instance.copy()) 
                    utterance_instance['dialogue_meta'] = dialogue_info
                    utterance_instance['dialogue_history'] = dialogue_history
                    yield id_, utterance_instance