File size: 3,974 Bytes
9dd2b0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90fb61a
834f06f
90fb61a
 
9dd2b0b
 
0a70980
 
9dd2b0b
 
 
 
 
1fe2591
9dd2b0b
e9c8bc9
9dd2b0b
 
 
 
 
e9c8bc9
a2e3a85
e3d7281
794f20e
9dd2b0b
589743e
 
9dd2b0b
 
 
 
e5d274a
9dd2b0b
 
eaf0075
402f076
7bfe5d8
7590452
 
7f6335b
402f076
7bfe5d8
9dd2b0b
 
 
90fb61a
 
 
916b8c3
 
e1dee54
4593ddd
3c71c81
 
 
 
 
 
 
90fb61a
834f06f
90fb61a
 
 
 
589743e
 
 
f7c38a2
f9fa9d8
589743e
299e9f0
 
 
 
916b8c3
ebde9b3
103763a
916b8c3
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
# coding=utf-8
'''DiscEvalMT: DiscEvalMT: Contrastive test sets for the evaluation of discourse in machine translation (v2)'''

import json
import datasets

logger = datasets.logging.get_logger(__name__)

_CITATION = '''\
@inproceedings{bawden-etal-2018-evaluating,
    title = "Evaluating Discourse Phenomena in Neural Machine Translation",
    author = "Bawden, Rachel and Sennrich, Rico and Birch, Alexandra and Haddow, Barry",
    booktitle = {{Proceedings of the 2018 Conference of the North {A}merican Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers)}},
    month = jun,
    year = "2018",
    address = "New Orleans, Louisiana",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/N18-1118",
    doi = "10.18653/v1/N18-1118",
    pages = "1304--1313"
}
'''

_DESCRIPTION = '''\
English-French hand-crafted contrastive test set to test anaphora and lexical choice
'''

_HOMEPAGE='https://github.com/rbawden/discourse-mt-test-sets/tree/master'

_LICENSE = 'CC-BY-SA-4.0'
 
_URLS = {
    'test-lexical_choice': 'lexical_choice/eval.jsonl',
    'test-anaphora': 'anaphora/eval.jsonl'
}


class DiscEvalMTConfig(datasets.BuilderConfig):
    '''BuilderConfig for DiscEvalMT.'''
    

    def __init__(self, evaltype: str, **kwargs):
        """BuilderConfig for DiscEvalMT.

        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        self.evaltype = evaltype
        if evaltype not in ['anaphora', 'lexical_choice']:
            raise ValueError("Invalid evaltype: %s. You must choose between 'anaphora' and 'lexical_choice' " % evaltype)
        super(DiscEvalMTConfig, self).__init__(**kwargs)

        


class DiscEvalMT(datasets.GeneratorBasedBuilder):
    '''DiscEvalMT: English-French contrastive test set for 2 discourse phenomena (anaphora and lexical cohesion)'''

    BUILDER_CONFIG_CLASS = DiscEvalMTConfig
    BUILDER_CONFIGS = [
        DiscEvalMTConfig(
            evaltype='anaphora',
            name='anaphora',
            version=datasets.Version('2.0.0'),
        ),
        DiscEvalMTConfig(
            evaltype='lexical_choice',
            name='lexical_choice',
            version=datasets.Version('2.0.0'),
        ),
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                                        "split": datasets.Value("string"), 
                                        "ex_num": datasets.Value("int64"),
                                        "type": datasets.Value("string"),
                                        "context_src": datasets.Value("string"),
                                        "current_src": datasets.Value("string"),
                                        "context_trg": datasets.Value("string"),
                                        "current_trg": datasets.Value("string"),
                                        "contrastive_context_trg": datasets.Value("string"),
                                        "contrastive_current_trg": datasets.Value("string"),
                                        "correct_or_semicorrect": datasets.Value("string")}),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
        )

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

        return datasets.SplitGenerator(name="test", gen_kwargs={'filepath': downloaded_files['test-' + self.config.evaltype]}),
               

    def _generate_examples(self, filepath):
        logger.info("generating examples from = %s", filepath)
        key = 0
        with open(filepath, encoding="utf-8") as f:
            for i, line in enumerate(f):
                
                example = json.loads(line)
                yield i, example