File size: 1,897 Bytes
b61620b
a0a398d
0f86d75
4747b67
b61620b
 
1699be0
0f86d75
 
cbccf14
 
0f86d75
 
cbccf14
 
 
4747b67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbccf14
 
 
afe164d
821db02
cbccf14
afe164d
cbccf14
 
 
b61620b
 
 
 
 
 
 
 
 
 
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
import json
import datasets
from datasets import GeneratorBasedBuilder, DatasetInfo, Split, SplitGenerator, Features, Value, Sequence

_BASE_URL = "https://drive.google.com/uc?export=download&id=12J5C6knWWPebLsjdZt0zCU4GKzDO5kGa"


class UzABSA(GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="uzabsa", version=VERSION,
                               description="UZABSA dataset for sentiment analysis in Uzbek"),
    ]

    def _info(self):
        return DatasetInfo(
            features=Features({
                "sentence_id": Value("string"),
                "text": Value("string"),
                "aspect_terms": Sequence({
                    "term": Value("string"),
                    "polarity": Value("string"),
                    "from": Value("int32"),
                    "to": Value("int32"),
                }),
                "aspect_categories": Sequence({
                    "category": Value("string"),
                    "polarity": Value("string"),
                }),
            })
        )

    def _split_generators(self, dl_manager):
        # Use the dl_manager to download and cache the data
        downloaded_file = dl_manager.download_and_extract(_BASE_URL)
        return [
            SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": downloaded_file}),
        ]

    def _generate_examples(self, filepath):
        # Now we'll read the jsonl format
        with open(filepath, 'r') as file:
            for line in file:
                record = json.loads(line.strip())
                yield record["sentence_id"], {
                    "sentence_id": record["sentence_id"],
                    "text": record["text"],
                    "aspect_terms": record["aspect_terms"],
                    "aspect_categories": record["aspect_categories"],
                }