File size: 1,362 Bytes
aa5a087
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb695a8
aa5a087
 
 
 
 
0d5e602
aa5a087
 
0d5e602
aa5a087
 
 
 
 
 
2e6cfa3
 
aa5a087
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
import os
import json
import datasets
import typing as tp

_LABELS = [
    'positive', 
    'negative'
]


class MARC(datasets.GeneratorBasedBuilder):

    def _info(self):
        return datasets.DatasetInfo(
            description=None, 
            features=datasets.Features({
                "text": datasets.Value("string"), 
                "label": datasets.features.ClassLabel(
                    names=_LABELS
                )
            }), 
            homepage=None, 
            citation='https://aclanthology.org/2022.lrec-1.317.pdf'
        )

    def _split_generators(self, dl_manager: datasets.DownloadManager) -> tp.List[datasets.SplitGenerator]:
        path = os.getcwd()
        train_filepath = os.path.join(path, 'train.json')
        dev_filepath = os.path.join(path, 'dev.json')
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={'filepath': train_filepath}), 
            datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={'filepath': dev_filepath}), 
        ]

    def _generate_examples(self, filepath):
        with open(filepath, 'r', encoding='utf-8') as fp:
            lines = json.load(fp)
        for idx, line in enumerate(lines):
            text = str(line['text'])
            label = int(line['label'])
            yield idx, {'text': text, 'label': label}