Datasets:
Delete loading script
Browse files- scicite.py +0 -154
scicite.py
DELETED
@@ -1,154 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
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 |
-
|
16 |
-
# Lint as: python3
|
17 |
-
"""TODO(scicite): Add a description here."""
|
18 |
-
|
19 |
-
|
20 |
-
import json
|
21 |
-
|
22 |
-
import datasets
|
23 |
-
|
24 |
-
|
25 |
-
_CITATION = """
|
26 |
-
@InProceedings{Cohan2019Structural,
|
27 |
-
author={Arman Cohan and Waleed Ammar and Madeleine Van Zuylen and Field Cady},
|
28 |
-
title={Structural Scaffolds for Citation Intent Classification in Scientific Publications},
|
29 |
-
booktitle={NAACL},
|
30 |
-
year={2019}
|
31 |
-
}
|
32 |
-
"""
|
33 |
-
|
34 |
-
_DESCRIPTION = """
|
35 |
-
This is a dataset for classifying citation intents in academic papers.
|
36 |
-
The main citation intent label for each Json object is specified with the label
|
37 |
-
key while the citation context is specified in with a context key. Example:
|
38 |
-
{
|
39 |
-
'string': 'In chacma baboons, male-infant relationships can be linked to both
|
40 |
-
formation of friendships and paternity success [30,31].'
|
41 |
-
'sectionName': 'Introduction',
|
42 |
-
'label': 'background',
|
43 |
-
'citingPaperId': '7a6b2d4b405439',
|
44 |
-
'citedPaperId': '9d1abadc55b5e0',
|
45 |
-
...
|
46 |
-
}
|
47 |
-
You may obtain the full information about the paper using the provided paper ids
|
48 |
-
with the Semantic Scholar API (https://api.semanticscholar.org/).
|
49 |
-
The labels are:
|
50 |
-
Method, Background, Result
|
51 |
-
"""
|
52 |
-
|
53 |
-
_SOURCE_NAMES = ["properNoun", "andPhrase", "acronym", "etAlPhrase", "explicit", "acronymParen", "nan"]
|
54 |
-
|
55 |
-
|
56 |
-
class Scicite(datasets.GeneratorBasedBuilder):
|
57 |
-
"""This is a dataset for classifying citation intents in academic papers."""
|
58 |
-
|
59 |
-
VERSION = datasets.Version("1.0.0")
|
60 |
-
|
61 |
-
def _info(self):
|
62 |
-
return datasets.DatasetInfo(
|
63 |
-
# This is the description that will appear on the datasets page.
|
64 |
-
description=_DESCRIPTION,
|
65 |
-
# datasets.features.FeatureConnectors
|
66 |
-
features=datasets.Features(
|
67 |
-
{
|
68 |
-
"string": datasets.Value("string"),
|
69 |
-
"sectionName": datasets.Value("string"),
|
70 |
-
"label": datasets.features.ClassLabel(names=["method", "background", "result"]),
|
71 |
-
"citingPaperId": datasets.Value("string"),
|
72 |
-
"citedPaperId": datasets.Value("string"),
|
73 |
-
"excerpt_index": datasets.Value("int32"),
|
74 |
-
"isKeyCitation": datasets.Value("bool"),
|
75 |
-
"label2": datasets.features.ClassLabel(
|
76 |
-
names=["supportive", "not_supportive", "cant_determine", "none"]
|
77 |
-
),
|
78 |
-
"citeEnd": datasets.Value("int64"),
|
79 |
-
"citeStart": datasets.Value("int64"),
|
80 |
-
"source": datasets.features.ClassLabel(names=_SOURCE_NAMES),
|
81 |
-
"label_confidence": datasets.Value("float32"),
|
82 |
-
"label2_confidence": datasets.Value("float32"),
|
83 |
-
"id": datasets.Value("string"),
|
84 |
-
}
|
85 |
-
),
|
86 |
-
# If there's a common (input, target) tuple from the features,
|
87 |
-
# specify them here. They'll be used if as_supervised=True in
|
88 |
-
# builder.as_dataset.
|
89 |
-
supervised_keys=None,
|
90 |
-
# Homepage of the dataset for documentation
|
91 |
-
homepage="https://github.com/allenai/scicite",
|
92 |
-
citation=_CITATION,
|
93 |
-
)
|
94 |
-
|
95 |
-
def _split_generators(self, dl_manager):
|
96 |
-
"""Returns SplitGenerators."""
|
97 |
-
archive = dl_manager.download("https://s3-us-west-2.amazonaws.com/ai2-s2-research/scicite/scicite.tar.gz")
|
98 |
-
return [
|
99 |
-
datasets.SplitGenerator(
|
100 |
-
name=datasets.Split.TRAIN,
|
101 |
-
gen_kwargs={
|
102 |
-
"filepath": "/".join(["scicite", "train.jsonl"]),
|
103 |
-
"files": dl_manager.iter_archive(archive),
|
104 |
-
},
|
105 |
-
),
|
106 |
-
datasets.SplitGenerator(
|
107 |
-
name=datasets.Split.VALIDATION,
|
108 |
-
gen_kwargs={"filepath": "/".join(["scicite", "dev.jsonl"]), "files": dl_manager.iter_archive(archive)},
|
109 |
-
),
|
110 |
-
datasets.SplitGenerator(
|
111 |
-
name=datasets.Split.TEST,
|
112 |
-
gen_kwargs={
|
113 |
-
"filepath": "/".join(["scicite", "test.jsonl"]),
|
114 |
-
"files": dl_manager.iter_archive(archive),
|
115 |
-
},
|
116 |
-
),
|
117 |
-
]
|
118 |
-
|
119 |
-
def _generate_examples(self, filepath, files):
|
120 |
-
"""Yields examples."""
|
121 |
-
for path, f in files:
|
122 |
-
if path == filepath:
|
123 |
-
unique_ids = {}
|
124 |
-
for line in f:
|
125 |
-
d = json.loads(line.decode("utf-8"))
|
126 |
-
unique_id = str(d["unique_id"])
|
127 |
-
if unique_id in unique_ids:
|
128 |
-
continue
|
129 |
-
unique_ids[unique_id] = True
|
130 |
-
yield unique_id, {
|
131 |
-
"string": d["string"],
|
132 |
-
"label": str(d["label"]),
|
133 |
-
"sectionName": str(d["sectionName"]),
|
134 |
-
"citingPaperId": str(d["citingPaperId"]),
|
135 |
-
"citedPaperId": str(d["citedPaperId"]),
|
136 |
-
"excerpt_index": int(d["excerpt_index"]),
|
137 |
-
"isKeyCitation": bool(d["isKeyCitation"]),
|
138 |
-
"label2": str(d.get("label2", "none")),
|
139 |
-
"citeEnd": _safe_int(d["citeEnd"]),
|
140 |
-
"citeStart": _safe_int(d["citeStart"]),
|
141 |
-
"source": str(d["source"]),
|
142 |
-
"label_confidence": float(d.get("label_confidence", 0.0)),
|
143 |
-
"label2_confidence": float(d.get("label2_confidence", 0.0)),
|
144 |
-
"id": str(d["id"]),
|
145 |
-
}
|
146 |
-
break
|
147 |
-
|
148 |
-
|
149 |
-
def _safe_int(a):
|
150 |
-
try:
|
151 |
-
# skip NaNs
|
152 |
-
return int(a)
|
153 |
-
except ValueError:
|
154 |
-
return -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|