kellywong commited on
Commit
b76220a
·
1 Parent(s): 79d70a4

update README.md

Browse files
Files changed (1) hide show
  1. README.md +185 -0
README.md CHANGED
@@ -1,3 +1,188 @@
1
  ---
 
2
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: en
3
  license: mit
4
+ datasets:
5
+ - DocRED
6
+ tags:
7
+ - lsr
8
+ - token-generation
9
+ inference: false
10
+ model-index:
11
+ - name: LSR
12
+ results:
13
+ - task:
14
+ type: token-generation
15
+ name: LSR
16
+ dataset:
17
+ name: DocRED (on development set)
18
+ type: DocRED
19
+ metrics:
20
+ - name: F1
21
+ type: f1
22
+ value: 0.55
23
+ - task:
24
+ type: token-generation
25
+ name: LSR
26
+ dataset:
27
+ name: DocRED (reported by authors in paper on development set)
28
+ type: DocRED
29
+ metrics:
30
+ - name: F1
31
+ type: f1
32
+ value: 0.55
33
  ---
34
+
35
+ # Relation Extraction
36
+ You can **test the model** at [SGNLP-Demo](https://sgnlp.aisingapore.net/relation-extraction).<br />
37
+ If you want to find out more information, please contact us at [email protected].
38
+
39
+ ## Table of Contents
40
+ - [Model Details](#model-details)
41
+ - [How to Get Started With the Model](#how-to-get-started-with-the-model)
42
+ - [Training](#training)
43
+ - [Model Parameters](#parameters)
44
+ - [Other Information](#other-information)
45
+
46
+ ## Model Details
47
+ **Model Name:** LSR
48
+ - **Description:** This is a neural network that induces a latent document-level graph and uses a refinement strategy that allows the model to incrementally aggregate relevant information for multi-hop reasoning. This particular model corresponds to the GloVe+LSR model described in the paper.
49
+ - **Paper:** Reasoning with Latent Structure Refinement for Document-Level Relation Extraction. Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, July 2020 (pp. 1546-1557).
50
+ - **Author(s):** Nan, G., Guo, Z., Sekulić, I., & Lu, W. (2020).
51
+ - **URL:** https://aclanthology.org/2020.acl-main.141/
52
+
53
+ # How to Get Started With the Model
54
+
55
+ ## Install Python package
56
+ SGnlp is an initiative by AI Singapore's NLP Hub. They aim to bridge the gap between research and industry, promote translational research, and encourage adoption of NLP techniques in the industry. <br><br> Various NLP models, other than relation extraction are available in the python package. You can try them out at [SGNLP-Demo](https://sgnlp.aisingapore.net/) | [SGNLP-Github](https://github.com/aisingapore/sgnlp).
57
+
58
+ ```python
59
+ pip install sgnlp
60
+
61
+ ```
62
+
63
+ ## Examples
64
+ For more full code (such as Relation-Extraction), please refer to this [github](https://github.com/aisingapore/sgnlp). <br> Alternatively, you can also try out the [SGNLP-Demo](https://sgnlp.aisingapore.net/relation-extraction) | [SGNLP-Docs](https://sgnlp.aisingapore.net/docs/api_reference/sgnlp.models.lsr.html) for Relation extraction using LSR model.
65
+
66
+ Example of Relation Extraction (using LSR model):
67
+ ```python
68
+ from sgnlp.models.lsr import LsrModel, LsrConfig, LsrPreprocessor, LsrPostprocessor
69
+ from transformers import cached_path
70
+
71
+ # Download files from azure blob storage
72
+ rel2id_path = cached_path('https://storage.googleapis.com/sgnlp/models/lsr/rel2id.json')
73
+ word2id_path = cached_path('https://storage.googleapis.com/sgnlp/models/lsr/word2id.json')
74
+ ner2id_path = cached_path('https://storage.googleapis.com/sgnlp/models/lsr/ner2id.json')
75
+ rel_info_path = cached_path('https://storage.googleapis.com/sgnlp/models/lsr/rel_info.json')
76
+
77
+ PRED_THRESHOLD = 0.3
78
+ preprocessor = LsrPreprocessor(rel2id_path=rel2id_path, word2id_path=word2id_path, ner2id_path=ner2id_path)
79
+ postprocessor = LsrPostprocessor.from_file_paths(rel2id_path=rel2id_path, rel_info_path=rel_info_path,
80
+ pred_threshold=PRED_THRESHOLD)
81
+
82
+ # Load model
83
+ config = LsrConfig.from_pretrained('https://storage.googleapis.com/sgnlp/models/lsr/v2/config.json')
84
+ model = LsrModel.from_pretrained('https://storage.googleapis.com/sgnlp/models/lsr/v2/pytorch_model.bin', config=config)
85
+ model.eval()
86
+
87
+ # DocRED-like instance
88
+ instance = {
89
+ "vertexSet": [[{"name": "Lark Force", "pos": [0, 2], "sent_id": 0, "type": "ORG"},
90
+ {"sent_id": 3, "type": "ORG", "pos": [2, 4], "name": "Lark Force"},
91
+ {"name": "Lark Force", "pos": [3, 5], "sent_id": 4, "type": "ORG"}],
92
+ [{"name": "Australian Army", "pos": [4, 6], "sent_id": 0, "type": "ORG"}],
93
+ [{"pos": [9, 11], "type": "TIME", "sent_id": 0, "name": "March 1941"}],
94
+ [{"name": "World War II", "pos": [12, 15], "sent_id": 0, "type": "MISC"}],
95
+ [{"name": "New Britain", "pos": [18, 20], "sent_id": 0, "type": "LOC"}],
96
+ [{"name": "New Ireland", "pos": [21, 23], "sent_id": 0, "type": "LOC"}],
97
+ [{"name": "John Scanlan", "pos": [6, 8], "sent_id": 1, "type": "PER"}],
98
+ [{"name": "Australia", "pos": [13, 14], "sent_id": 1, "type": "LOC"}],
99
+ [{"name": "Rabaul", "pos": [17, 18], "sent_id": 1, "type": "LOC"},
100
+ {"name": "Rabaul", "pos": [12, 13], "sent_id": 3, "type": "LOC"}],
101
+ [{"name": "Kavieng", "pos": [19, 20], "sent_id": 1, "type": "LOC"},
102
+ {"name": "Kavieng", "pos": [14, 15], "sent_id": 3, "type": "LOC"}],
103
+ [{"pos": [22, 24], "type": "MISC", "sent_id": 1, "name": "SS Katoomba"}],
104
+ [{"pos": [25, 27], "type": "MISC", "sent_id": 1, "name": "MV Neptuna"}],
105
+ [{"name": "HMAT Zealandia", "pos": [28, 30], "sent_id": 1, "type": "MISC"}],
106
+ [{"name": "Imperial Japanese Army", "pos": [8, 11], "sent_id": 3, "type": "ORG"}],
107
+ [{"pos": [18, 20], "type": "TIME", "sent_id": 3, "name": "January 1942"}],
108
+ [{"name": "Japan", "pos": [8, 9], "sent_id": 4, "type": "LOC"}],
109
+ [{"pos": [12, 13], "type": "MISC", "sent_id": 4, "name": "NCOs"}],
110
+ [{"name": "USS Sturgeon", "pos": [20, 22], "sent_id": 4, "type": "MISC"}],
111
+ [{"sent_id": 4, "type": "MISC", "pos": [27, 29], "name": "Montevideo Maru"}],
112
+ [{"name": "Japanese", "pos": [5, 6], "sent_id": 5, "type": "LOC"}],
113
+ [{"pos": [15, 16], "type": "NUM", "sent_id": 5, "name": "1,050"}],
114
+ [{"pos": [17, 18], "type": "NUM", "sent_id": 5, "name": "1,053"}]],
115
+ "labels": [
116
+ {"r": "P607", "h": 1, "t": 3, "evidence": [0]},
117
+ {"r": "P17", "h": 1, "t": 7, "evidence": [0, 1]},
118
+ {"r": "P241", "h": 6, "t": 1, "evidence": [0, 1]},
119
+ {"r": "P607", "h": 6, "t": 3, "evidence": [0, 1]},
120
+ {"r": "P27", "h": 6, "t": 7, "evidence": [0, 1]},
121
+ {"r": "P1344", "h": 7, "t": 3, "evidence": [0, 1]},
122
+ {"r": "P607", "h": 13, "t": 3, "evidence": [0, 3]},
123
+ {"r": "P17", "h": 13, "t": 15, "evidence": [3, 4, 5]},
124
+ {"r": "P17", "h": 13, "t": 19, "evidence": [3, 4, 5]},
125
+ {"r": "P1344", "h": 15, "t": 3, "evidence": [0, 3, 4, 5]},
126
+ {"r": "P172", "h": 15, "t": 19, "evidence": [4, 5]},
127
+ {"r": "P607", "h": 17, "t": 3, "evidence": [0, 4]},
128
+ {"r": "P17", "h": 11, "t": 7, "evidence": [1]},
129
+ {"r": "P17", "h": 12, "t": 7, "evidence": [0, 1]},
130
+ {"r": "P137", "h": 0, "t": 1, "evidence": [0, 1]},
131
+ {"r": "P571", "h": 0, "t": 2, "evidence": [0]},
132
+ {"r": "P607", "h": 0, "t": 3, "evidence": [0]},
133
+ {"r": "P17", "h": 0, "t": 7, "evidence": [0, 1]}],
134
+ "title": "Lark Force",
135
+ "sents": [
136
+ ["Lark", "Force", "was", "an", "Australian", "Army", "formation", "established", "in", "March", "1941",
137
+ "during", "World", "War", "II", "for", "service", "in", "New", "Britain", "and", "New", "Ireland", "."],
138
+ ["Under", "the", "command", "of", "Lieutenant", "Colonel", "John", "Scanlan", ",", "it", "was", "raised", "in",
139
+ "Australia", "and", "deployed", "to", "Rabaul", "and", "Kavieng", ",", "aboard", "SS", "Katoomba", ",", "MV",
140
+ "Neptuna", "and", "HMAT", "Zealandia", ",", "to", "defend", "their", "strategically", "important", "harbours",
141
+ "and", "airfields", "."],
142
+ ["The", "objective", "of", "the", "force", ",", "was", "to", "maintain", "a", "forward", "air", "observation",
143
+ "line", "as", "long", "as", "possible", "and", "to", "make", "the", "enemy", "fight", "for", "this", "line",
144
+ "rather", "than", "abandon", "it", "at", "the", "first", "threat", "as", "the", "force", "was", "considered",
145
+ "too", "small", "to", "withstand", "any", "invasion", "."],
146
+ ["Most", "of", "Lark", "Force", "was", "captured", "by", "the", "Imperial", "Japanese", "Army", "after",
147
+ "Rabaul", "and", "Kavieng", "were", "captured", "in", "January", "1942", "."],
148
+ ["The", "officers", "of", "Lark", "Force", "were", "transported", "to", "Japan", ",", "however", "the", "NCOs",
149
+ "and", "men", "were", "unfortunately", "torpedoed", "by", "the", "USS", "Sturgeon", "while", "being",
150
+ "transported", "aboard", "the", "Montevideo", "Maru", "."],
151
+ ["Only", "a", "handful", "of", "the", "Japanese", "crew", "were", "rescued", ",", "with", "none", "of", "the",
152
+ "between", "1,050", "and", "1,053", "prisoners", "aboard", "surviving", "as", "they", "were", "still",
153
+ "locked", "below", "deck", "."]
154
+ ]
155
+ }
156
+
157
+ tensor_doc = preprocessor([instance])
158
+ output = model(**tensor_doc)
159
+
160
+ result = postprocessor(output.prediction, [instance])
161
+
162
+
163
+
164
+ ```
165
+
166
+
167
+ # Training
168
+ The training datasets can be retrieved from Permuted dataset derived from Linguistic Data Consortium's (LDC) Wall Street Journal (WSJ) dataset.
169
+ Please contact the authors to get the dataset if you have a valid LDC license.
170
+
171
+ #### Training Results
172
+ - **Training Time:** ~17 hours for 100 epochs on a single V100 GPU.
173
+ - **Datasets:** Retrieved from [DocRED](https://github.com/thunlp/DocRED/tree/master/data)
174
+ - **Training Config:** Not available.
175
+
176
+ # Model Parameters
177
+ - **Model Weights:** [link](https://storage.googleapis.com/sgnlp/models/lsr/pytorch_model.bin)
178
+ - **Model Config:** [link](https://storage.googleapis.com/sgnlp/models/lsr/config.json)
179
+ - **Model Inputs:** Coreference clusters of entities, relations between clusters of entities, and text.
180
+ - **Model Outputs:** Scores of all possible relation labels between all possible pairs of entity clusters.
181
+ - **Model Size:** ~85MB
182
+ - **Model Inference Info:** Not available.
183
+ - **Usage Scenarios:** Knowledge graph building.
184
+
185
+ # Other Information
186
+ - **Original Code:** [link](https://github.com/nanguoshun/LSR)
187
+ - **Additional Information**: CAVEATS: The model trained in this paper alone is not sufficient to do extract relations from a document. It requires other models to perform entity recognition and coreference between the entities. For this demo, two other pretrained models from AllenNLP is used: Fine Grained Name Entity Recognition and Coreference SpanBERT.
188
+