Delete loading script
Browse files- senti_ws.py +0 -132
senti_ws.py
DELETED
@@ -1,132 +0,0 @@
|
|
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 |
-
"""SentiWS: German-language resource for sentiment analysis, pos-tagging"""
|
16 |
-
|
17 |
-
|
18 |
-
import os
|
19 |
-
|
20 |
-
import datasets
|
21 |
-
|
22 |
-
|
23 |
-
_CITATION = """\
|
24 |
-
@INPROCEEDINGS{remquahey2010,
|
25 |
-
title = {SentiWS -- a Publicly Available German-language Resource for Sentiment Analysis},
|
26 |
-
booktitle = {Proceedings of the 7th International Language Resources and Evaluation (LREC'10)},
|
27 |
-
author = {Remus, R. and Quasthoff, U. and Heyer, G.},
|
28 |
-
year = {2010}
|
29 |
-
}
|
30 |
-
"""
|
31 |
-
|
32 |
-
_DESCRIPTION = """\
|
33 |
-
SentimentWortschatz, or SentiWS for short, is a publicly available German-language resource for sentiment analysis, and pos-tagging. The POS tags are ["NN", "VVINF", "ADJX", "ADV"] -> ["noun", "verb", "adjective", "adverb"], and positive and negative polarity bearing words are weighted within the interval of [-1, 1].
|
34 |
-
"""
|
35 |
-
|
36 |
-
_HOMEPAGE = ""
|
37 |
-
|
38 |
-
_LICENSE = "Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License"
|
39 |
-
|
40 |
-
_URLs = ["https://downloads.wortschatz-leipzig.de/etc/SentiWS/SentiWS_v2.0.zip"]
|
41 |
-
|
42 |
-
|
43 |
-
class SentiWS(datasets.GeneratorBasedBuilder):
|
44 |
-
"""SentiWS: German-language resource for sentiment analysis, pos-tagging"""
|
45 |
-
|
46 |
-
VERSION = datasets.Version("1.1.0")
|
47 |
-
|
48 |
-
BUILDER_CONFIGS = [
|
49 |
-
datasets.BuilderConfig(name="pos-tagging", version=VERSION, description="This covers pos-tagging task"),
|
50 |
-
datasets.BuilderConfig(
|
51 |
-
name="sentiment-scoring",
|
52 |
-
version=VERSION,
|
53 |
-
description="This covers the sentiment-scoring in [-1, 1] corresponding to (negative, positive) sentiment",
|
54 |
-
),
|
55 |
-
]
|
56 |
-
|
57 |
-
DEFAULT_CONFIG_NAME = "pos-tagging"
|
58 |
-
|
59 |
-
def _info(self):
|
60 |
-
|
61 |
-
if (
|
62 |
-
self.config.name == "pos-tagging"
|
63 |
-
): # the pos-tags are ["NN", "VVINF", "ADJX", "ADV"] -> ["noun", "verb", "adjective", "adverb"]
|
64 |
-
features = datasets.Features(
|
65 |
-
{
|
66 |
-
"word": datasets.Value("string"),
|
67 |
-
"pos-tag": datasets.ClassLabel(names=["NN", "VVINF", "ADJX", "ADV"]),
|
68 |
-
}
|
69 |
-
)
|
70 |
-
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
71 |
-
features = datasets.Features(
|
72 |
-
{
|
73 |
-
"word": datasets.Value("string"),
|
74 |
-
"sentiment-score": datasets.Value("float32"),
|
75 |
-
}
|
76 |
-
)
|
77 |
-
return datasets.DatasetInfo(
|
78 |
-
# This is the description that will appear on the datasets page.
|
79 |
-
description=_DESCRIPTION,
|
80 |
-
# This defines the different columns of the dataset and their types
|
81 |
-
features=features, # Here we define them above because they are different between the two configurations
|
82 |
-
# If there's a common (input, target) tuple from the features,
|
83 |
-
# specify them here. They'll be used if as_supervised=True in
|
84 |
-
# builder.as_dataset.
|
85 |
-
supervised_keys=None,
|
86 |
-
# Homepage of the dataset for documentation
|
87 |
-
homepage=_HOMEPAGE,
|
88 |
-
# License for the dataset if available
|
89 |
-
license=_LICENSE,
|
90 |
-
# Citation for the dataset
|
91 |
-
citation=_CITATION,
|
92 |
-
)
|
93 |
-
|
94 |
-
def _split_generators(self, dl_manager):
|
95 |
-
"""Returns SplitGenerators."""
|
96 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
97 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
98 |
-
|
99 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
100 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
101 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
102 |
-
my_urls = _URLs
|
103 |
-
data_dir = dl_manager.download_and_extract(my_urls)
|
104 |
-
return [
|
105 |
-
datasets.SplitGenerator(
|
106 |
-
name=datasets.Split.TRAIN,
|
107 |
-
# These kwargs will be passed to _generate_examples
|
108 |
-
gen_kwargs={
|
109 |
-
"sourcefiles": [
|
110 |
-
os.path.join(data_dir[0], f)
|
111 |
-
for f in ["SentiWS_v2.0_Positive.txt", "SentiWS_v2.0_Negative.txt"]
|
112 |
-
],
|
113 |
-
"split": "train",
|
114 |
-
},
|
115 |
-
),
|
116 |
-
]
|
117 |
-
|
118 |
-
def _generate_examples(self, sourcefiles, split):
|
119 |
-
"""Yields examples."""
|
120 |
-
# TODO: This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
|
121 |
-
# It is in charge of opening the given file and yielding (key, example) tuples from the dataset
|
122 |
-
# The key is not important, it's more here for legacy reason (legacy from tfds)
|
123 |
-
for file_idx, filepath in enumerate(sourcefiles):
|
124 |
-
with open(filepath, encoding="utf-8") as f:
|
125 |
-
for id_, row in enumerate(f):
|
126 |
-
word = row.split("|")[0]
|
127 |
-
if self.config.name == "pos-tagging":
|
128 |
-
tag = row.split("|")[1].split("\t")[0]
|
129 |
-
yield f"{file_idx}_{id_}", {"word": word, "pos-tag": tag}
|
130 |
-
else:
|
131 |
-
sentiscore = row.split("|")[1].split("\t")[1]
|
132 |
-
yield f"{file_idx}_{id_}", {"word": word, "sentiment-score": float(sentiscore)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|