ukp-data-admin commited on
Commit
3075d10
1 Parent(s): 60ca810

Upload UKP_ASPECT.py

Browse files
Files changed (1) hide show
  1. UKP_ASPECT.py +148 -0
UKP_ASPECT.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Add description
15
+ """TexPrax: Data collected during the project https://texprax.de/ """
16
+
17
+
18
+ import csv
19
+ import os
20
+ import ast
21
+ #import json
22
+
23
+ import datasets
24
+
25
+ # TODO: Add citation
26
+ _CITATION = """\
27
+ @inproceedings{reimers2019classification,
28
+ title={Classification and Clustering of Arguments with Contextualized Word Embeddings},
29
+ author={Reimers, Nils and Schiller, Benjamin and Beck, Tilman and Daxenberger, Johannes and Stab, Christian and Gurevych, Iryna},
30
+ booktitle={Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics},
31
+ pages={567--578},
32
+ year={2019}
33
+ }
34
+ """
35
+
36
+ # TODO: Add description
37
+ _DESCRIPTION = """\
38
+ The UKP ASPECT Corpus includes 3,595 sentence pairs over 28 controversial topics. The sentences were crawled from a large web crawl and identified as arguments for a given topic using the ArgumenText system. The sampling and matching of the sentence pairs is described in the paper. Then, the argument similarity annotation was done via crowdsourcing. Each crowd worker could choose from four annotation options (the exact guidelines are provided in the Appendix of the paper).
39
+ """
40
+
41
+ # TODO: Add link
42
+ _HOMEPAGE = "https://tudatalib.ulb.tu-darmstadt.de/handle/tudatalib/1998"
43
+
44
+ # TODO: Add license
45
+ _LICENSE = "Creative Commons Attribution-NonCommercial 3.0"
46
+
47
+
48
+ # TODO: Add tudatalib urls here!
49
+ _URL = "https://tudatalib.ulb.tu-darmstadt.de/bitstream/handle/tudatalib/1998/UKP_ASPECT.zip?sequence=1&isAllowed=y"
50
+
51
+ class UKPAspectConfig(datasets.BuilderConfig):
52
+ """BuilderConfig for UKP ASPECT."""
53
+ def __init__(self, features, data_url, citation, url, label_classes=("False", "True"), **kwargs):
54
+ super(UKPAspectConfig, self).__init__(**kwargs)
55
+
56
+
57
+ class UKPAspectDataset(datasets.GeneratorBasedBuilder):
58
+ """3,595 sentence pairs over 28 controversial topics. The sentences were crawled from a large web crawl and identified as arguments for a given topic using the ArgumenText system. The sampling and matching of the sentence pairs is described in the paper. Then, the argument similarity annotation was done via crowdsourcing. Each crowd worker could choose from four annotation options (the exact guidelines are provided in the Appendix of the paper)."""
59
+
60
+ VERSION = datasets.Version("1.1.0")
61
+
62
+ BUILDER_CONFIGS = [
63
+ datasets.BuilderConfig(name="standard", version=VERSION, description="Sentence pairs annotated with argument similarity")
64
+ ]
65
+
66
+ DEFAULT_CONFIG_NAME = "standard" # It's not mandatory to have a default configuration. Just use one if it make sense.
67
+
68
+ def _info(self):
69
+ if self.config.name == "standard": # This is the name of the configuration selected in BUILDER_CONFIGS above
70
+ features = datasets.Features(
71
+ {
72
+ # Note: ID consists of <dialog-id_sentence-id_turn-id>
73
+ "topic": datasets.Value("string"),
74
+ "sentence_1": datasets.Value("string"),
75
+ "sentence_2": datasets.Value("string"),
76
+ "label": datasets.features.ClassLabel(
77
+ names=[
78
+ "NS",
79
+ "SS",
80
+ "DTORCD",
81
+ "HS",
82
+ ]),
83
+ "subsplit": datasets.Value("string"),
84
+ # These are the features of your dataset like images, labels ...
85
+ }
86
+ )
87
+ else:
88
+ raise ValueError(f'The only available config is "standard", but "{self.config.name}" was given')
89
+ return datasets.DatasetInfo(
90
+ # This is the description that will appear on the datasets page.
91
+ description=_DESCRIPTION,
92
+ # This defines the different columns of the dataset and their types
93
+ features=features, # Here we define them above because they are different between the two configurations
94
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
95
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
96
+ # supervised_keys=("sentence", "label"),
97
+ # Homepage of the dataset for documentation
98
+ homepage=_HOMEPAGE,
99
+ # License for the dataset if available
100
+ license=_LICENSE,
101
+ # Citation for the dataset
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager):
106
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
107
+ # TODO: Add your splits. .zip files will automatically be extracted, so you don't have to worry about them.
108
+ if self.config.name == "standard":
109
+ urls = _URL
110
+ data_dir = dl_manager.download_and_extract(urls)
111
+ return [
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.ALL,
114
+ # These kwargs will be passed to _generate_examples
115
+ gen_kwargs={
116
+ "filepath": os.path.join(data_dir, "UKP_ASPECT.tsv"),
117
+ "split": "all",
118
+ },
119
+ )
120
+ ]
121
+ else:
122
+ raise ValueError(f'The only available config is "standard", but "{self.config.name}" was given')
123
+
124
+
125
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
126
+ def _generate_examples(self, filepath, split):
127
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
128
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
129
+ with open(filepath, encoding="utf-8") as f:
130
+ creader = csv.reader(f, delimiter='\t', quotechar='"')
131
+ next(creader) # skip header
132
+ for key, row in enumerate(creader):
133
+ # TODO: Use the same keys here as in the datasets.Features of _info(self)
134
+ if self.config.name == "standard":
135
+ topic, sentence_1, sentence_2, label = row
136
+
137
+ # Yields examples as (key, example) tuples
138
+ yield key, {
139
+ "topic": topic,
140
+ "sentence_1": sentence_1,
141
+ "sentence_2": sentence_2,
142
+ "label": label,
143
+ }
144
+ else:
145
+ raise ValueError(f'The only available config is "standard", but "{self.config.name}" was given')
146
+
147
+
148
+