Unindent code
Browse files- scicite.py +44 -44
scicite.py
CHANGED
|
@@ -183,52 +183,52 @@ class SciciteDataset(datasets.GeneratorBasedBuilder):
|
|
| 183 |
examples = [json.loads(line) for line in file]
|
| 184 |
break
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
for example in examples:
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
example["unique_id"] = example["unique_id"] + "_duplicate"
|
| 192 |
else:
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
"citingPaperId": str(example["citingPaperId"]),
|
| 202 |
-
"citedPaperId": str(example["citedPaperId"]),
|
| 203 |
-
"excerpt_index": int(example["excerpt_index"]),
|
| 204 |
-
"isKeyCitation": bool(example["isKeyCitation"]),
|
| 205 |
-
"label2": str(example.get("label2", "none")),
|
| 206 |
-
"citeEnd": _safe_int(example["citeEnd"]),
|
| 207 |
-
"citeStart": _safe_int(example["citeStart"]),
|
| 208 |
-
"source": str(example["source"]),
|
| 209 |
-
"label_confidence": float(
|
| 210 |
-
example.get("label_confidence", np.nan)
|
| 211 |
-
),
|
| 212 |
-
"label2_confidence": float(
|
| 213 |
-
example.get("label2_confidence", np.nan)
|
| 214 |
-
),
|
| 215 |
-
"id": str(example["id"]),
|
| 216 |
-
"unique_id": str(example["unique_id"]),
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
elif self.config.schema == "bigbio_text":
|
| 220 |
-
for example in examples:
|
| 221 |
-
if "label2" in example:
|
| 222 |
-
labels = [example["label"], example["label2"]]
|
| 223 |
-
else:
|
| 224 |
-
labels = [example["label"]]
|
| 225 |
-
|
| 226 |
-
yield str(example["unique_id"]), {
|
| 227 |
-
"id": example["unique_id"],
|
| 228 |
-
"document_id": example["citingPaperId"],
|
| 229 |
-
"text": example["string"],
|
| 230 |
-
"labels": labels,
|
| 231 |
-
}
|
| 232 |
|
| 233 |
|
| 234 |
def _safe_int(a):
|
|
|
|
| 183 |
examples = [json.loads(line) for line in file]
|
| 184 |
break
|
| 185 |
|
| 186 |
+
# Preprocesses examples
|
| 187 |
+
keys = set()
|
| 188 |
+
for example in examples:
|
| 189 |
+
# Fixes duplicate keys
|
| 190 |
+
if example["unique_id"] in keys:
|
| 191 |
+
example["unique_id"] = example["unique_id"] + "_duplicate"
|
| 192 |
+
else:
|
| 193 |
+
keys.add(example["unique_id"])
|
| 194 |
+
|
| 195 |
+
if self.config.schema == "source":
|
| 196 |
+
for example in examples:
|
| 197 |
+
yield str(example["unique_id"]), {
|
| 198 |
+
"string": example["string"],
|
| 199 |
+
"label": str(example["label"]),
|
| 200 |
+
"sectionName": str(example["sectionName"]),
|
| 201 |
+
"citingPaperId": str(example["citingPaperId"]),
|
| 202 |
+
"citedPaperId": str(example["citedPaperId"]),
|
| 203 |
+
"excerpt_index": int(example["excerpt_index"]),
|
| 204 |
+
"isKeyCitation": bool(example["isKeyCitation"]),
|
| 205 |
+
"label2": str(example.get("label2", "none")),
|
| 206 |
+
"citeEnd": _safe_int(example["citeEnd"]),
|
| 207 |
+
"citeStart": _safe_int(example["citeStart"]),
|
| 208 |
+
"source": str(example["source"]),
|
| 209 |
+
"label_confidence": float(
|
| 210 |
+
example.get("label_confidence", np.nan)
|
| 211 |
+
),
|
| 212 |
+
"label2_confidence": float(
|
| 213 |
+
example.get("label2_confidence", np.nan)
|
| 214 |
+
),
|
| 215 |
+
"id": str(example["id"]),
|
| 216 |
+
"unique_id": str(example["unique_id"]),
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
elif self.config.schema == "bigbio_text":
|
| 220 |
for example in examples:
|
| 221 |
+
if "label2" in example:
|
| 222 |
+
labels = [example["label"], example["label2"]]
|
|
|
|
| 223 |
else:
|
| 224 |
+
labels = [example["label"]]
|
| 225 |
+
|
| 226 |
+
yield str(example["unique_id"]), {
|
| 227 |
+
"id": example["unique_id"],
|
| 228 |
+
"document_id": example["citingPaperId"],
|
| 229 |
+
"text": example["string"],
|
| 230 |
+
"labels": labels,
|
| 231 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
|
| 234 |
def _safe_int(a):
|