Datasets:
Tasks:
Token Classification
Modalities:
Text
Sub-tasks:
sentiment-classification
Languages:
Polish
Size:
1K - 10K
License:
Albert Sawczyn
commited on
Commit
•
e35dccf
1
Parent(s):
552bea8
update script
Browse files- aspectemo.py +86 -72
aspectemo.py
CHANGED
@@ -1,104 +1,118 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
import datasets
|
5 |
from datasets import DownloadManager
|
6 |
from datasets.info import SupervisedKeysData
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
Sentiment Analysis"""
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
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 |
-
|
46 |
-
"
|
47 |
-
|
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 |
-
"
|
59 |
-
"
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
)
|
64 |
}
|
65 |
),
|
66 |
-
supervised_keys=SupervisedKeysData(input="
|
67 |
-
homepage=
|
|
|
|
|
68 |
)
|
69 |
|
70 |
-
def _split_generators(
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
return [
|
74 |
datasets.SplitGenerator(
|
75 |
name=datasets.Split.TRAIN,
|
76 |
-
gen_kwargs={
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
gen_kwargs={"filepath": downloaded_files["validation"]},
|
81 |
),
|
82 |
datasets.SplitGenerator(
|
83 |
name=datasets.Split.TEST,
|
84 |
-
gen_kwargs={
|
|
|
|
|
|
|
85 |
),
|
86 |
]
|
87 |
|
88 |
def _generate_examples(
|
89 |
-
|
|
|
|
|
90 |
) -> Generator[Tuple[int, Dict[str, str]], None, None]:
|
91 |
-
with open(filepath,
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
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])
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
import json
|
16 |
+
import os
|
17 |
+
from typing import Generator, Tuple, Dict, List
|
18 |
|
19 |
import datasets
|
20 |
from datasets import DownloadManager
|
21 |
from datasets.info import SupervisedKeysData
|
22 |
|
23 |
+
_CITATION = """@misc{11321/849,
|
24 |
+
title = {{AspectEmo} 1.0: Multi-Domain Corpus of Consumer Reviews for Aspect-Based Sentiment Analysis},
|
25 |
+
author = {Koco{\'n}, Jan and Radom, Jarema and Kaczmarz-Wawryk, Ewa and Wabnic, Kamil and Zaj{\c a}czkowska, Ada and Za{\'s}ko-Zieli{\'n}ska, Monika},
|
26 |
+
url = {http://hdl.handle.net/11321/849},
|
27 |
+
note = {{CLARIN}-{PL} digital repository},
|
28 |
+
copyright = {The {MIT} License},
|
29 |
+
year = {2021}
|
30 |
+
}"""
|
31 |
+
|
32 |
+
_DESCRIPTION = """AspectEmo dataset: Multi-Domain Corpus of Consumer Reviews for Aspect-Based
|
33 |
Sentiment Analysis"""
|
34 |
|
35 |
+
_HOMEPAGE = "https://clarin-pl.eu/dspace/handle/11321/849"
|
36 |
+
|
37 |
+
_LICENSE = "The MIT License"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
_URLs = {
|
40 |
+
"1.0": "https://huggingface.co/datasets/clarin-pl/aspectemo/resolve/main/data/aspectemo1.zip",
|
41 |
+
# '2.0': "",
|
|
|
42 |
}
|
43 |
|
44 |
+
_CLASSES = ["a_plus_s", "a_zero", "a_amb", "a_minus_m", "O", "a_minus_s", "a_plus_m"]
|
45 |
+
|
46 |
|
47 |
class AspectEmo(datasets.GeneratorBasedBuilder):
|
48 |
+
VERSION = datasets.Version("1.0.0")
|
49 |
+
|
50 |
+
BUILDER_CONFIGS = [
|
51 |
+
datasets.BuilderConfig(
|
52 |
+
name="1.0",
|
53 |
+
version=VERSION,
|
54 |
+
description="AspectEmo 1.0 Corpus, used in the original paper.",
|
55 |
+
),
|
56 |
+
# datasets.BuilderConfig(
|
57 |
+
# name="2.0",
|
58 |
+
# version=VERSION,
|
59 |
+
# description="",
|
60 |
+
# ),
|
61 |
+
]
|
62 |
+
|
63 |
+
DEFAULT_CONFIG_NAME = "1.0"
|
64 |
+
|
65 |
def _info(self) -> datasets.DatasetInfo:
|
66 |
return datasets.DatasetInfo(
|
67 |
description=_DESCRIPTION,
|
68 |
features=datasets.Features(
|
69 |
{
|
70 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
71 |
+
"labels": datasets.Sequence(
|
72 |
+
datasets.features.ClassLabel(
|
73 |
+
names=_CLASSES, num_classes=len(_CLASSES)
|
74 |
+
)
|
75 |
+
),
|
76 |
}
|
77 |
),
|
78 |
+
supervised_keys=SupervisedKeysData(input="tokens", output="labels"),
|
79 |
+
homepage=_HOMEPAGE,
|
80 |
+
license=_LICENSE,
|
81 |
+
citation=_CITATION,
|
82 |
)
|
83 |
|
84 |
+
def _split_generators(
|
85 |
+
self, dl_manager: DownloadManager
|
86 |
+
) -> List[datasets.SplitGenerator]:
|
87 |
+
my_urls = _URLs[self.config.name]
|
88 |
+
data_dir = dl_manager.download_and_extract(my_urls)
|
89 |
+
|
90 |
return [
|
91 |
datasets.SplitGenerator(
|
92 |
name=datasets.Split.TRAIN,
|
93 |
+
gen_kwargs={
|
94 |
+
"filepath": os.path.join(data_dir, "data.json"),
|
95 |
+
"split": "train",
|
96 |
+
},
|
|
|
97 |
),
|
98 |
datasets.SplitGenerator(
|
99 |
name=datasets.Split.TEST,
|
100 |
+
gen_kwargs={
|
101 |
+
"filepath": os.path.join(data_dir, "data.json"),
|
102 |
+
"split": "test",
|
103 |
+
},
|
104 |
),
|
105 |
]
|
106 |
|
107 |
def _generate_examples(
|
108 |
+
self,
|
109 |
+
filepath: str,
|
110 |
+
split: str,
|
111 |
) -> Generator[Tuple[int, Dict[str, str]], None, None]:
|
112 |
+
with open(filepath, encoding="utf-8") as f:
|
113 |
+
data = json.load(f)[split]
|
114 |
+
for id_, row in data.items():
|
115 |
+
yield id_, {
|
116 |
+
"tokens": row["tokens"],
|
117 |
+
"labels": row["labels"],
|
118 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|