Datasets:

Languages:
English
Size:
n<1K
ArneBinder commited on
Commit
6bc6221
·
1 Parent(s): 692e846

Create cdcp.py

Browse files
Files changed (1) hide show
  1. cdcp.py +161 -0
cdcp.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The Cornell eRulemaking Corpus (CDCP) dataset for English Argumentation Mining."""
2
+ import glob
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import datasets
7
+
8
+ _CITATION = """\
9
+ @inproceedings{niculae-etal-2017-argument,
10
+ title = "Argument Mining with Structured {SVM}s and {RNN}s",
11
+ author = "Niculae, Vlad and
12
+ Park, Joonsuk and
13
+ Cardie, Claire",
14
+ booktitle = "Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
15
+ month = jul,
16
+ year = "2017",
17
+ address = "Vancouver, Canada",
18
+ publisher = "Association for Computational Linguistics",
19
+ url = "https://aclanthology.org/P17-1091",
20
+ doi = "10.18653/v1/P17-1091",
21
+ pages = "985--995",
22
+ abstract = "We propose a novel factor graph model for argument mining, designed for settings in which the argumentative relations in a document do not necessarily form a tree structure. (This is the case in over 20{\\%} of the web comments dataset we release.) Our model jointly learns elementary unit type classification and argumentative relation prediction. Moreover, our model supports SVM and RNN parametrizations, can enforce structure constraints (e.g., transitivity), and can express dependencies between adjacent relations and propositions. Our approaches outperform unstructured baselines in both web comments and argumentative essay datasets.",
23
+ }
24
+ """
25
+
26
+ _DESCRIPTION = "The CDCP dataset for English Argumentation Mining"
27
+
28
+ _HOMEPAGE = ""
29
+
30
+ _LICENSE = ""
31
+
32
+
33
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
34
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
35
+ _URL = "https://facultystaff.richmond.edu/~jpark/data/cdcp_acl17.zip"
36
+
37
+ _VERSION = datasets.Version("1.0.0")
38
+
39
+ _SPAN_CLASS_LABELS = ["fact", "policy", "reference", "testimony", "value"]
40
+ _RELATION_CLASS_LABELS = ["evidence", "reason"]
41
+
42
+
43
+ class CDCP(datasets.GeneratorBasedBuilder):
44
+ """CDCP is a argumentation mining dataset."""
45
+
46
+ BUILDER_CONFIGS = [datasets.BuilderConfig(name="default")]
47
+
48
+ DEFAULT_CONFIG_NAME = "default" # type: ignore
49
+
50
+ def _info(self):
51
+ features = datasets.Features(
52
+ {
53
+ "id": datasets.Value("string"),
54
+ "text": datasets.Value("string"),
55
+ "propositions": datasets.Sequence(
56
+ {
57
+ "start": datasets.Value("int32"),
58
+ "end": datasets.Value("int32"),
59
+ "label": datasets.ClassLabel(names=_SPAN_CLASS_LABELS),
60
+ # urls are replaced with the string "__URL__" in the text. This contains the original url.
61
+ "url": datasets.Value("string"),
62
+ }
63
+ ),
64
+ "relations": datasets.Sequence(
65
+ {
66
+ "head": datasets.Value("int32"),
67
+ "tail": datasets.Value("int32"),
68
+ "label": datasets.ClassLabel(names=_RELATION_CLASS_LABELS),
69
+ }
70
+ ),
71
+ }
72
+ )
73
+
74
+ return datasets.DatasetInfo(
75
+ # This is the description that will appear on the datasets page.
76
+ description=_DESCRIPTION,
77
+ # This defines the different columns of the dataset and their types
78
+ features=features, # Here we define them above because they are different between the two configurations
79
+ # If there's a common (input, target) tuple from the features,
80
+ # specify them here. They'll be used if as_supervised=True in
81
+ # builder.as_dataset.
82
+ supervised_keys=None,
83
+ # Homepage of the dataset for documentation
84
+ homepage=_HOMEPAGE,
85
+ # License for the dataset if available
86
+ license=_LICENSE,
87
+ # Citation for the dataset
88
+ citation=_CITATION,
89
+ )
90
+
91
+ def _split_generators(self, dl_manager):
92
+ """Returns SplitGenerators."""
93
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
94
+
95
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
96
+ # 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.
97
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
98
+
99
+ base_path = Path(dl_manager.download_and_extract(_URL)) / "cdcp"
100
+
101
+ return [
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TRAIN, gen_kwargs={"path": base_path / "train"}
104
+ ),
105
+ datasets.SplitGenerator(
106
+ name=datasets.Split.TEST, gen_kwargs={"path": base_path / "test"}
107
+ ),
108
+ ]
109
+
110
+ def _generate_examples(self, path):
111
+ """Yields examples."""
112
+ # This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
113
+ # It is in charge of opening the given file and yielding (key, example) tuples from the dataset
114
+ # The key is not important, it's more here for legacy reason (legacy from tfds)
115
+
116
+ _id = 0
117
+ text_file_names = sorted(glob.glob(f"{path}/*.txt"))
118
+ for text_file_name in text_file_names:
119
+ txt_fn = Path(text_file_name)
120
+ ann_fn = txt_fn.with_suffix(".ann.json")
121
+ with open(txt_fn, encoding="utf-8") as f:
122
+ text = f.read()
123
+ with open(ann_fn, encoding="utf-8") as f:
124
+ annotations = json.load(f)
125
+ # example content of annotations:
126
+ # {
127
+ # 'evidences': [[[8, 8], 7]],
128
+ # 'prop_labels': ['testimony', 'testimony', 'value'],
129
+ # 'prop_offsets': [[0, 114], [114, 209], [209, 235]],
130
+ # 'reasons': [[[2, 2], 1], [ 0, 0], 2]],
131
+ # 'evidences': [[[2, 2], 1], [ 0, 0], 2]],
132
+ # 'url': {
133
+ # "3": "http://usa.visa.com/personal/using_visa/checkout_fees/",
134
+ # "4": "http://usa.visa.com/download/merchants/surcharging-faq-by-merchants.pdf"
135
+ # }
136
+ # }
137
+ propositions = [
138
+ {
139
+ "start": start,
140
+ "end": end,
141
+ "label": label,
142
+ "url": annotations["url"].get(str(idx), ""),
143
+ }
144
+ for idx, ((start, end), label) in enumerate(
145
+ zip(annotations["prop_offsets"], annotations["prop_labels"])
146
+ )
147
+ ]
148
+ relations = []
149
+ for (tail_first_idx, tail_last_idx), head_idx in annotations["evidences"]:
150
+ for tail_idx in range(tail_first_idx, tail_last_idx + 1):
151
+ relations.append({"head": head_idx, "tail": tail_idx, "label": "evidence"})
152
+ for (tail_first_idx, tail_last_idx), head_idx in annotations["reasons"]:
153
+ for tail_idx in range(tail_first_idx, tail_last_idx + 1):
154
+ relations.append({"head": head_idx, "tail": tail_idx, "label": "reason"})
155
+ yield _id, {
156
+ "id": txt_fn.stem,
157
+ "text": text,
158
+ "propositions": propositions,
159
+ "relations": relations,
160
+ }
161
+ _id += 1