DGME commited on
Commit
8c93873
·
verified ·
1 Parent(s): 2b9df22

Upload _ontonotes.py

Browse files
Files changed (1) hide show
  1. _ontonotes.py +80 -0
_ontonotes.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import datasets
3
+ import json
4
+ from pathlib import Path
5
+
6
+ _ROOT = Path(__file__).resolve().parent
7
+
8
+ _DATA_POS = {
9
+ "train": "./data/g_train.json",
10
+ "test": "./data/g_test.json",
11
+ "val": "./data/g_dev.json",
12
+ "extra": "./data/augmented_train.json"
13
+ }
14
+
15
+ _DESCIPTION = "contains original ontonotes train/dev/test dataset from https://github.com/shimaokasonse/NFGEC, as well as newly augmented training dataset. "
16
+
17
+
18
+ class ontonotes(datasets.GeneratorBasedBuilder):
19
+ VERSION = datasets.Version("1.0.0")
20
+ def _info(self):
21
+ return datasets.DatasetInfo(
22
+ description=_DESCIPTION,
23
+ features=datasets.Features({
24
+ "mention_span": datasets.Value("string"),
25
+ "right_context_token": datasets.Value("string"),
26
+ "left_context_token": datasets.Value("string"),
27
+ "y_str": datasets.Sequence(datasets.Value("string")),
28
+ "y_type_str": datasets.Sequence(datasets.Value("string")),
29
+ "y": datasets.Sequence(datasets.Value("int32")),
30
+ "y_type": datasets.Sequence(datasets.Value("int32")),
31
+ "annot_id": datasets.Value("string"),
32
+ })
33
+ )
34
+
35
+ def _split_generators(self, dl_manager):
36
+ return [
37
+ datasets.SplitGenerator(
38
+ name=datasets.Split.TRAIN,
39
+ gen_kwargs={
40
+ "path": _DATA_POS["train"], "split": "train"
41
+ }
42
+
43
+ ),
44
+ datasets.SplitGenerator(
45
+ name=datasets.Split.TEST,
46
+ gen_kwargs={
47
+ "path": _DATA_POS["test"], "split": "test"
48
+ }
49
+ ),
50
+ datasets.SplitGenerator(
51
+ name=datasets.Split.VALIDATION,
52
+ gen_kwargs={
53
+ "path": _DATA_POS["val"], "split": "val"
54
+ }
55
+ ),
56
+ datasets.SplitGenerator(
57
+ name="extra",
58
+ gen_kwargs={
59
+ "path": _DATA_POS["extra"], "split": "extra"
60
+ }
61
+ )
62
+ ]
63
+
64
+ def _generate_examples(self, path, split):
65
+ # f 是多行 JSON
66
+ with open(path, "r") as f:
67
+ data = [json.loads(line) for line in f]
68
+
69
+ for i, example in enumerate(data):
70
+ yield i, {
71
+ "mention_span": example["mention_span"],
72
+ "right_context_token": example["right_context_token"],
73
+ "left_context_token": example["left_context_token"],
74
+ "y_str": example["y_str"],
75
+ "y_type_str": example["y_type_str"],
76
+ "y": example["y"],
77
+ "y_type": example["y_type"],
78
+ "annot_id": example["annot_id"]
79
+ }
80
+