bowdbeg commited on
Commit
ccb1b32
·
1 Parent(s): 78259a9

add redocred

Browse files
data/dev_revised.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:655cf867f0dac11c81994f9bcd0fa78c0ec02ca55267191e8bb87dc10b2970f3
3
+ size 632045
data/rel_info.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ef27efff537ba89ae66f6f4e60e4908d4df3860a4c2819ea94fa5ed696bdc70
3
+ size 1037
data/test_revised.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d6ad71e4f76973314151fe28408fcbb8053593ac165fdf568de523316c1bbdbc
3
+ size 620220
data/train_revised.json.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b4aa312f3a8074373f24a59e230bffdf39e8fb7bbb39ba0f4e7a19fd4d1d3f4f
3
+ size 3659860
redocred.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """DocRED: A Large-Scale Document-Level Relation Extraction Dataset"""
2
+
3
+ import json
4
+
5
+ import datasets
6
+
7
+ _CITATION = """\
8
+ @inproceedings{yao-etal-2019-docred,
9
+ title = "{D}oc{RED}: A Large-Scale Document-Level Relation Extraction Dataset",
10
+ author = "Yao, Yuan and
11
+ Ye, Deming and
12
+ Li, Peng and
13
+ Han, Xu and
14
+ Lin, Yankai and
15
+ Liu, Zhenghao and
16
+ Liu, Zhiyuan and
17
+ Huang, Lixin and
18
+ Zhou, Jie and
19
+ Sun, Maosong",
20
+ booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
21
+ month = jul,
22
+ year = "2019",
23
+ address = "Florence, Italy",
24
+ publisher = "Association for Computational Linguistics",
25
+ url = "https://aclanthology.org/P19-1074",
26
+ doi = "10.18653/v1/P19-1074",
27
+ pages = "764--777",
28
+ }
29
+ """
30
+
31
+ _DESCRIPTION = """\
32
+ This repository is copied from https://huggingface.co/datasets/thunlp/docred and changed the files to change Re-DocRED.\
33
+ Multiple entities in a document generally exhibit complex inter-sentence relations, and cannot be well handled by \
34
+ existing relation extraction (RE) methods that typically focus on extracting intra-sentence relations for single \
35
+ entity pairs. In order to accelerate the research on document-level RE, we introduce DocRED, a new dataset constructed \
36
+ from Wikipedia and Wikidata with three features:
37
+ - DocRED annotates both named entities and relations, and is the largest human-annotated dataset for document-level RE from plain text.
38
+ - DocRED requires reading multiple sentences in a document to extract entities and infer their relations by synthesizing all information of the document.
39
+ - Along with the human-annotated data, we also offer large-scale distantly supervised data, which enables DocRED to be adopted for both supervised and weakly supervised scenarios.
40
+ """
41
+
42
+ _URLS = {
43
+ "dev": "data/dev_revised.json.gz",
44
+ "train": "data/train_revised.json.gz",
45
+ "test": "data/test.json.gz",
46
+ "rel_info": "data/rel_info.json.gz",
47
+ }
48
+
49
+
50
+ class DocRed(datasets.GeneratorBasedBuilder):
51
+ """DocRED: A Large-Scale Document-Level Relation Extraction Dataset"""
52
+
53
+ def _info(self):
54
+ return datasets.DatasetInfo(
55
+ description=_DESCRIPTION,
56
+ features=datasets.Features(
57
+ {
58
+ "title": datasets.Value("string"),
59
+ "sents": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
60
+ "vertexSet": [
61
+ [
62
+ {
63
+ "name": datasets.Value("string"),
64
+ "sent_id": datasets.Value("int32"),
65
+ "pos": datasets.features.Sequence(datasets.Value("int32")),
66
+ "type": datasets.Value("string"),
67
+ }
68
+ ]
69
+ ],
70
+ "labels": datasets.features.Sequence(
71
+ {
72
+ "head": datasets.Value("int32"),
73
+ "tail": datasets.Value("int32"),
74
+ "relation_id": datasets.Value("string"),
75
+ "relation_text": datasets.Value("string"),
76
+ "evidence": datasets.features.Sequence(datasets.Value("int32")),
77
+ }
78
+ ),
79
+ }
80
+ ),
81
+ supervised_keys=None,
82
+ homepage="https://github.com/thunlp/DocRED",
83
+ citation=_CITATION,
84
+ )
85
+
86
+ def _split_generators(self, dl_manager):
87
+ downloads = dl_manager.download_and_extract(_URLS)
88
+ return [
89
+ datasets.SplitGenerator(
90
+ name=datasets.Split.VALIDATION,
91
+ gen_kwargs={"filepath": downloads["dev"], "rel_info": downloads["rel_info"]},
92
+ ),
93
+ datasets.SplitGenerator(
94
+ name=datasets.Split.TEST, gen_kwargs={"filepath": downloads["test"], "rel_info": downloads["rel_info"]}
95
+ ),
96
+ datasets.SplitGenerator(
97
+ name="train_annotated",
98
+ gen_kwargs={"filepath": downloads["train_annotated"], "rel_info": downloads["rel_info"]},
99
+ ),
100
+ datasets.SplitGenerator(
101
+ name="train_distant",
102
+ gen_kwargs={"filepath": downloads["train_distant"], "rel_info": downloads["rel_info"]},
103
+ ),
104
+ ]
105
+
106
+ def _generate_examples(self, filepath, rel_info):
107
+ """Generate DocRED examples."""
108
+
109
+ with open(rel_info, encoding="utf-8") as f:
110
+ relation_name_map = json.load(f)
111
+ with open(filepath, encoding="utf-8") as f:
112
+ data = json.load(f)
113
+
114
+ for idx, example in enumerate(data):
115
+
116
+ # Test set has no labels - Results need to be uploaded to Codalab
117
+ if "labels" not in example.keys():
118
+ example["labels"] = []
119
+
120
+ for label in example["labels"]:
121
+ # Rename and include full relation names
122
+ label["relation_text"] = relation_name_map[label["r"]]
123
+ label["relation_id"] = label["r"]
124
+ label["head"] = label["h"]
125
+ label["tail"] = label["t"]
126
+ del label["r"]
127
+ del label["h"]
128
+ del label["t"]
129
+
130
+ yield idx, example