Albert Sawczyn commited on
Commit
4796b54
1 Parent(s): 9183b66

add data and loader

Browse files
Files changed (4) hide show
  1. aspectemo.py +104 -0
  2. data/test.tsv +0 -0
  3. data/train.tsv +0 -0
  4. data/val.tsv +0 -0
aspectemo.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ from typing import List, Generator, Tuple, Dict
3
+
4
+ import datasets
5
+ from datasets import DownloadManager
6
+ from datasets.info import SupervisedKeysData
7
+
8
+ _DESCRIPTION = """AspectEmo 1.0 dataset: Multi-Domain Corpus of Consumer Reviews for Aspect-Based
9
+ Sentiment Analysis"""
10
+
11
+ _CLASSES = ['O',
12
+ 'B-a_plus_m',
13
+ 'B-a_minus_m',
14
+ 'B-a_zero',
15
+ 'B-a_minus_s',
16
+ 'B-a_plus_s',
17
+ 'B-a_amb',
18
+ 'B-a_minus_m:B-a_minus_m',
19
+ 'B-a_minus_m:B-a_minus_m:B-a_minus_m',
20
+ 'B-a_plus_m:B-a_plus_m',
21
+ 'B-a_plus_m:B-a_plus_m:B-a_plus_m',
22
+ 'B-a_zero:B-a_zero:B-a_zero',
23
+ 'B-a_zero:B-a_zero',
24
+ 'I-a_plus_m',
25
+ 'B-a_zero:B-a_plus_m',
26
+ 'B-a_minus_m:B-a_zero',
27
+ 'B-a_minus_s:B-a_minus_s:B-a_minus_s',
28
+ 'B-a_amb:B-a_amb',
29
+ 'I-a_minus_m',
30
+ 'B-a_minus_s:B-a_minus_s',
31
+ 'B-a_plus_s:B-a_plus_s:B-a_plus_s',
32
+ 'B-a_plus_m:B-a_plus_m:B-a_plus_m:B-a_plus_m:B-a_plus_m:B-a_plus_m',
33
+ 'B-a_plus_m:B-a_amb',
34
+ 'B-a_minus_m:B-a_plus_m',
35
+ 'B-a_amb:B-a_amb:B-a_amb',
36
+ 'I-a_zero',
37
+ 'B-a_plus_s:B-a_plus_s',
38
+ 'B-a_plus_m:B-a_plus_s',
39
+ 'B-a_plus_m:B-a_zero',
40
+ 'B-a_zero:B-a_zero:B-a_zero:B-a_zero:B-a_zero:B-a_zero',
41
+ 'B-a_zero:B-a_minus_m',
42
+ 'B-a_amb:B-a_plus_s',
43
+ 'B-a_zero:B-a_minus_s']
44
+
45
+ _URLS = {
46
+ "train": "https://huggingface.co/datasets/clarin-pl/aspectemo/resolve/main/data/train.tsv",
47
+ "validation": "https://huggingface.co/datasets/clarin-pl/aspectemo/resolve/main/data/val.tsv",
48
+ "test": "https://huggingface.co/datasets/clarin-pl/aspectemo/resolve/main/data/test.tsv",
49
+ }
50
+
51
+
52
+ class AspectEmo(datasets.GeneratorBasedBuilder):
53
+ def _info(self) -> datasets.DatasetInfo:
54
+ return datasets.DatasetInfo(
55
+ description=_DESCRIPTION,
56
+ features=datasets.Features(
57
+ {
58
+ "orth": datasets.Sequence(datasets.Value("string")),
59
+ "ctag": datasets.Sequence(datasets.Value("string")),
60
+ "sentiment": datasets.Sequence(datasets.features.ClassLabel(
61
+ names=_CLASSES,
62
+ num_classes=len(_CLASSES)
63
+ )),
64
+ }
65
+ ),
66
+ supervised_keys=SupervisedKeysData(input="orth", output="sentiment"),
67
+ homepage="https://clarin-pl.eu/dspace/handle/11321/849",
68
+ )
69
+
70
+ def _split_generators(self, dl_manager: DownloadManager) -> List[datasets.SplitGenerator]:
71
+ urls_to_download = _URLS
72
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
73
+ return [
74
+ datasets.SplitGenerator(
75
+ name=datasets.Split.TRAIN,
76
+ gen_kwargs={"filepath": downloaded_files["train"]},
77
+ ),
78
+ datasets.SplitGenerator(
79
+ name=datasets.Split.VALIDATION,
80
+ gen_kwargs={"filepath": downloaded_files["validation"]},
81
+ ),
82
+ datasets.SplitGenerator(
83
+ name=datasets.Split.TEST,
84
+ gen_kwargs={"filepath": downloaded_files["test"]},
85
+ ),
86
+ ]
87
+
88
+ def _generate_examples(
89
+ self, filepath: str
90
+ ) -> Generator[Tuple[int, Dict[str, str]], None, None]:
91
+ with open(filepath, "r", encoding="utf-8") as f:
92
+ reader = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
93
+ next(reader, None) # skip header
94
+ id_, orth, ctag, sentiment = set(), [], [], []
95
+ for line in reader:
96
+ if not line:
97
+ assert len(id_) == 1
98
+ yield id_.pop(), {"orth": orth, "ctag": ctag, "sentiment": sentiment, }
99
+ id_, orth, ctag, sentiment = set(), [], [], []
100
+ else:
101
+ id_.add(line[0])
102
+ orth.append(line[1])
103
+ ctag.append(line[2])
104
+ sentiment.append(line[3])
data/test.tsv ADDED
The diff for this file is too large to render. See raw diff
 
data/train.tsv ADDED
The diff for this file is too large to render. See raw diff
 
data/val.tsv ADDED
The diff for this file is too large to render. See raw diff