Datasets:

ArneBinder commited on
Commit
82c1a28
·
1 Parent(s): 1835d7d

Create scidtb_argmin.py

Browse files
Files changed (1) hide show
  1. scidtb_argmin.py +147 -0
scidtb_argmin.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The SciDTB-Argmin dataset for Argumentation Mining on English scientific abstracts."""
2
+ import glob
3
+ import json
4
+ import os.path
5
+ from pathlib import Path
6
+
7
+ import datasets
8
+
9
+ _CITATION = """\
10
+ @inproceedings{accuosto-saggion-2019-transferring,
11
+ title = "Transferring Knowledge from Discourse to Arguments: A Case Study with Scientific Abstracts",
12
+ author = "Accuosto, Pablo and
13
+ Saggion, Horacio",
14
+ booktitle = "Proceedings of the 6th Workshop on Argument Mining",
15
+ month = aug,
16
+ year = "2019",
17
+ address = "Florence, Italy",
18
+ publisher = "Association for Computational Linguistics",
19
+ url = "https://aclanthology.org/W19-4505",
20
+ doi = "10.18653/v1/W19-4505",
21
+ pages = "41--51",
22
+ abstract = "In this work we propose to leverage resources available with discourse-level annotations to facilitate the identification of argumentative components and relations in scientific texts, which has been recognized as a particularly challenging task. In particular, we implement and evaluate a transfer learning approach in which contextualized representations learned from discourse parsing tasks are used as input of argument mining models. As a pilot application, we explore the feasibility of using automatically identified argumentative components and relations to predict the acceptance of papers in computer science venues. In order to conduct our experiments, we propose an annotation scheme for argumentative units and relations and use it to enrich an existing corpus with an argumentation layer.",
23
+ }
24
+
25
+ """
26
+
27
+ _DESCRIPTION = (
28
+ "The SciDTB-Argmin dataset for Argumentation Mining on English scientific abstracts."
29
+ )
30
+
31
+ _HOMEPAGE = ""
32
+
33
+ _LICENSE = ""
34
+
35
+
36
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
37
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
38
+ _URL = "http://scientmin.taln.upf.edu/argmin/scidtb_argmin_annotations.tgz"
39
+
40
+ _VERSION = datasets.Version("1.0.0")
41
+
42
+ _SPAN_CLASS_LABELS = [
43
+ "proposal",
44
+ "assertion",
45
+ "result",
46
+ "observation",
47
+ "means",
48
+ "description",
49
+ "none",
50
+ ]
51
+ _RELATION_CLASS_LABELS = ["support", "additional", "detail", "sequence", "none"]
52
+
53
+
54
+ class SciDTBArgmin(datasets.GeneratorBasedBuilder):
55
+ """CDCP is a argumentation mining dataset."""
56
+
57
+ BUILDER_CONFIGS = [datasets.BuilderConfig(name="default")]
58
+
59
+ DEFAULT_CONFIG_NAME = "default" # type: ignore
60
+
61
+ def _info(self):
62
+ features = datasets.Features(
63
+ {
64
+ "id": datasets.Value("string"),
65
+ "data": datasets.Sequence(
66
+ {
67
+ "token": datasets.Value("string"),
68
+ "unit-bio": datasets.ClassLabel(names=["B", "I", "O"]),
69
+ "unit-label": datasets.ClassLabel(names=_SPAN_CLASS_LABELS),
70
+ "role": datasets.ClassLabel(names=_RELATION_CLASS_LABELS),
71
+ "parent-offset": datasets.Value("int32"),
72
+ # "parent-offset": datasets.Value("string"),
73
+ }
74
+ ),
75
+ }
76
+ )
77
+
78
+ return datasets.DatasetInfo(
79
+ # This is the description that will appear on the datasets page.
80
+ description=_DESCRIPTION,
81
+ # This defines the different columns of the dataset and their types
82
+ features=features, # Here we define them above because they are different between the two configurations
83
+ # If there's a common (input, target) tuple from the features,
84
+ # specify them here. They'll be used if as_supervised=True in
85
+ # builder.as_dataset.
86
+ supervised_keys=None,
87
+ # Homepage of the dataset for documentation
88
+ homepage=_HOMEPAGE,
89
+ # License for the dataset if available
90
+ license=_LICENSE,
91
+ # Citation for the dataset
92
+ citation=_CITATION,
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ """Returns SplitGenerators."""
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
+
103
+ path = dl_manager.download_and_extract(_URL)
104
+
105
+ return [
106
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"path": path}),
107
+ ]
108
+
109
+ def _generate_examples(self, path):
110
+ """Yields examples."""
111
+ # This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
112
+ # It is in charge of opening the given file and yielding (key, example) tuples from the dataset
113
+ # The key is not important, it's more here for legacy reason (legacy from tfds)
114
+
115
+ _id = 0
116
+ conll_file_names = sorted(glob.glob(f"{path}/*.conll"))
117
+ for conll_file_name in conll_file_names:
118
+ data = []
119
+ with open(conll_file_name, encoding="utf-8") as f:
120
+ for line in f:
121
+ # example content for some lines:
122
+ # reading I-proposal-none-0
123
+ # . I-proposal-none-0
124
+ # We B-means-detail-1
125
+ # observe I-means-detail-1
126
+ # , I-means-detail-1
127
+ # identify I-means-detail-1
128
+
129
+ token, annotation = line.strip().split("\t")
130
+ unit_bio, unit_label, role, parent_offset_str = annotation.split(
131
+ "-", maxsplit=3
132
+ )
133
+ parent_offset = int(parent_offset_str)
134
+ data.append(
135
+ {
136
+ "token": token,
137
+ "unit-bio": unit_bio,
138
+ "unit-label": unit_label,
139
+ "role": role,
140
+ "parent-offset": parent_offset,
141
+ }
142
+ )
143
+ yield _id, {
144
+ "id": Path(conll_file_name).stem,
145
+ "data": data,
146
+ }
147
+ _id += 1