KoichiYasuoka commited on
Commit
e384b95
·
1 Parent(s): 0ef6f8e

model improved

Browse files
Files changed (4) hide show
  1. config.json +510 -256
  2. maker.py +27 -15
  3. pytorch_model.bin +2 -2
  4. ud.py +60 -29
config.json CHANGED
@@ -33,267 +33,521 @@
33
  "hidden_activation": "gelu",
34
  "hidden_size": 768,
35
  "id2label": {
36
- "0": "ADJ",
37
- "1": "ADJ|l-acl",
38
- "2": "ADJ|l-advcl",
39
- "3": "ADJ|l-amod",
40
- "4": "ADJ|l-ccomp",
41
- "5": "ADJ|l-csubj",
42
- "6": "ADJ|l-csubj:outer",
43
- "7": "ADJ|l-nmod",
44
- "8": "ADJ|l-nsubj",
45
- "9": "ADJ|l-obj",
46
- "10": "ADJ|l-obl",
47
- "11": "ADJ|r-acl",
48
- "12": "ADJ|r-amod",
49
- "13": "ADJ|r-dep",
50
- "14": "ADJ|root",
51
- "15": "ADP",
52
- "16": "ADP|l-case",
53
- "17": "ADP|r-case",
54
- "18": "ADP|r-fixed",
55
- "19": "ADV",
56
- "20": "ADV|l-advcl",
57
- "21": "ADV|l-advmod",
58
- "22": "ADV|l-obj",
59
- "23": "ADV|r-dep",
60
- "24": "ADV|root",
61
- "25": "AUX",
62
- "26": "AUX|Polarity=Neg",
63
- "27": "AUX|Polarity=Neg|r-aux",
64
- "28": "AUX|Polarity=Neg|r-fixed",
65
- "29": "AUX|r-aux",
66
- "30": "AUX|r-cop",
67
- "31": "AUX|r-fixed",
68
- "32": "AUX|root",
69
- "33": "CCONJ",
70
- "34": "CCONJ|l-cc",
71
- "35": "CCONJ|r-cc",
72
- "36": "DET",
73
- "37": "DET|l-det",
74
- "38": "INTJ",
75
- "39": "INTJ|l-discourse",
76
- "40": "INTJ|r-discourse",
77
- "41": "INTJ|root",
78
- "42": "NOUN",
79
- "43": "NOUN|Polarity=Neg",
80
- "44": "NOUN|Polarity=Neg|l-obl",
81
- "45": "NOUN|Polarity=Neg|root",
82
- "46": "NOUN|l-acl",
83
- "47": "NOUN|l-advcl",
84
- "48": "NOUN|l-ccomp",
85
- "49": "NOUN|l-compound",
86
- "50": "NOUN|l-csubj",
87
- "51": "NOUN|l-csubj:outer",
88
- "52": "NOUN|l-nmod",
89
- "53": "NOUN|l-nsubj",
90
- "54": "NOUN|l-nsubj:outer",
91
- "55": "NOUN|l-obj",
92
- "56": "NOUN|l-obl",
93
- "57": "NOUN|r-compound",
94
- "58": "NOUN|r-nmod",
95
- "59": "NOUN|r-nsubj",
96
- "60": "NOUN|root",
97
- "61": "NUM",
98
- "62": "NUM|l-advcl",
99
- "63": "NUM|l-compound",
100
- "64": "NUM|l-nmod",
101
- "65": "NUM|l-nsubj",
102
- "66": "NUM|l-nsubj:outer",
103
- "67": "NUM|l-nummod",
104
- "68": "NUM|l-obj",
105
- "69": "NUM|l-obl",
106
- "70": "NUM|r-compound",
107
- "71": "NUM|root",
108
- "72": "PART",
109
- "73": "PART|l-mark",
110
- "74": "PART|r-mark",
111
- "75": "PRON",
112
- "76": "PRON|l-acl",
113
- "77": "PRON|l-advcl",
114
- "78": "PRON|l-nmod",
115
- "79": "PRON|l-nsubj",
116
- "80": "PRON|l-nsubj:outer",
117
- "81": "PRON|l-obj",
118
- "82": "PRON|l-obl",
119
- "83": "PRON|root",
120
- "84": "PROPN",
121
- "85": "PROPN|l-acl",
122
- "86": "PROPN|l-advcl",
123
- "87": "PROPN|l-compound",
124
- "88": "PROPN|l-nmod",
125
- "89": "PROPN|l-nsubj",
126
- "90": "PROPN|l-nsubj:outer",
127
- "91": "PROPN|l-obj",
128
- "92": "PROPN|l-obl",
129
- "93": "PROPN|r-compound",
130
- "94": "PROPN|r-nmod",
131
- "95": "PROPN|root",
132
- "96": "PUNCT",
133
- "97": "PUNCT|l-punct",
134
- "98": "PUNCT|r-punct",
135
- "99": "SCONJ",
136
- "100": "SCONJ|l-dep",
137
- "101": "SCONJ|r-fixed",
138
- "102": "SCONJ|r-mark",
139
- "103": "SYM",
140
- "104": "SYM|l-compound",
141
- "105": "SYM|l-dep",
142
- "106": "SYM|l-nmod",
143
- "107": "SYM|l-obl",
144
- "108": "SYM|r-compound",
145
- "109": "SYM|r-dep",
146
- "110": "VERB",
147
- "111": "VERB|l-acl",
148
- "112": "VERB|l-advcl",
149
- "113": "VERB|l-ccomp",
150
- "114": "VERB|l-compound",
151
- "115": "VERB|l-csubj",
152
- "116": "VERB|l-csubj:outer",
153
- "117": "VERB|l-nmod",
154
- "118": "VERB|l-obj",
155
- "119": "VERB|l-obl",
156
- "120": "VERB|r-acl",
157
- "121": "VERB|r-advcl",
158
- "122": "VERB|r-compound",
159
- "123": "VERB|root",
160
- "124": "X",
161
- "125": "X|l-nmod",
162
- "126": "X|r-dep",
163
- "127": "X|r-goeswith"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  },
165
  "initializer_cutoff_factor": 2.0,
166
  "initializer_range": 0.02,
167
  "intermediate_size": 1152,
168
  "label2id": {
169
- "ADJ": 0,
170
- "ADJ|l-acl": 1,
171
- "ADJ|l-advcl": 2,
172
- "ADJ|l-amod": 3,
173
- "ADJ|l-ccomp": 4,
174
- "ADJ|l-csubj": 5,
175
- "ADJ|l-csubj:outer": 6,
176
- "ADJ|l-nmod": 7,
177
- "ADJ|l-nsubj": 8,
178
- "ADJ|l-obj": 9,
179
- "ADJ|l-obl": 10,
180
- "ADJ|r-acl": 11,
181
- "ADJ|r-amod": 12,
182
- "ADJ|r-dep": 13,
183
- "ADJ|root": 14,
184
- "ADP": 15,
185
- "ADP|l-case": 16,
186
- "ADP|r-case": 17,
187
- "ADP|r-fixed": 18,
188
- "ADV": 19,
189
- "ADV|l-advcl": 20,
190
- "ADV|l-advmod": 21,
191
- "ADV|l-obj": 22,
192
- "ADV|r-dep": 23,
193
- "ADV|root": 24,
194
- "AUX": 25,
195
- "AUX|Polarity=Neg": 26,
196
- "AUX|Polarity=Neg|r-aux": 27,
197
- "AUX|Polarity=Neg|r-fixed": 28,
198
- "AUX|r-aux": 29,
199
- "AUX|r-cop": 30,
200
- "AUX|r-fixed": 31,
201
- "AUX|root": 32,
202
- "CCONJ": 33,
203
- "CCONJ|l-cc": 34,
204
- "CCONJ|r-cc": 35,
205
- "DET": 36,
206
- "DET|l-det": 37,
207
- "INTJ": 38,
208
- "INTJ|l-discourse": 39,
209
- "INTJ|r-discourse": 40,
210
- "INTJ|root": 41,
211
- "NOUN": 42,
212
- "NOUN|Polarity=Neg": 43,
213
- "NOUN|Polarity=Neg|l-obl": 44,
214
- "NOUN|Polarity=Neg|root": 45,
215
- "NOUN|l-acl": 46,
216
- "NOUN|l-advcl": 47,
217
- "NOUN|l-ccomp": 48,
218
- "NOUN|l-compound": 49,
219
- "NOUN|l-csubj": 50,
220
- "NOUN|l-csubj:outer": 51,
221
- "NOUN|l-nmod": 52,
222
- "NOUN|l-nsubj": 53,
223
- "NOUN|l-nsubj:outer": 54,
224
- "NOUN|l-obj": 55,
225
- "NOUN|l-obl": 56,
226
- "NOUN|r-compound": 57,
227
- "NOUN|r-nmod": 58,
228
- "NOUN|r-nsubj": 59,
229
- "NOUN|root": 60,
230
- "NUM": 61,
231
- "NUM|l-advcl": 62,
232
- "NUM|l-compound": 63,
233
- "NUM|l-nmod": 64,
234
- "NUM|l-nsubj": 65,
235
- "NUM|l-nsubj:outer": 66,
236
- "NUM|l-nummod": 67,
237
- "NUM|l-obj": 68,
238
- "NUM|l-obl": 69,
239
- "NUM|r-compound": 70,
240
- "NUM|root": 71,
241
- "PART": 72,
242
- "PART|l-mark": 73,
243
- "PART|r-mark": 74,
244
- "PRON": 75,
245
- "PRON|l-acl": 76,
246
- "PRON|l-advcl": 77,
247
- "PRON|l-nmod": 78,
248
- "PRON|l-nsubj": 79,
249
- "PRON|l-nsubj:outer": 80,
250
- "PRON|l-obj": 81,
251
- "PRON|l-obl": 82,
252
- "PRON|root": 83,
253
- "PROPN": 84,
254
- "PROPN|l-acl": 85,
255
- "PROPN|l-advcl": 86,
256
- "PROPN|l-compound": 87,
257
- "PROPN|l-nmod": 88,
258
- "PROPN|l-nsubj": 89,
259
- "PROPN|l-nsubj:outer": 90,
260
- "PROPN|l-obj": 91,
261
- "PROPN|l-obl": 92,
262
- "PROPN|r-compound": 93,
263
- "PROPN|r-nmod": 94,
264
- "PROPN|root": 95,
265
- "PUNCT": 96,
266
- "PUNCT|l-punct": 97,
267
- "PUNCT|r-punct": 98,
268
- "SCONJ": 99,
269
- "SCONJ|l-dep": 100,
270
- "SCONJ|r-fixed": 101,
271
- "SCONJ|r-mark": 102,
272
- "SYM": 103,
273
- "SYM|l-compound": 104,
274
- "SYM|l-dep": 105,
275
- "SYM|l-nmod": 106,
276
- "SYM|l-obl": 107,
277
- "SYM|r-compound": 108,
278
- "SYM|r-dep": 109,
279
- "VERB": 110,
280
- "VERB|l-acl": 111,
281
- "VERB|l-advcl": 112,
282
- "VERB|l-ccomp": 113,
283
- "VERB|l-compound": 114,
284
- "VERB|l-csubj": 115,
285
- "VERB|l-csubj:outer": 116,
286
- "VERB|l-nmod": 117,
287
- "VERB|l-obj": 118,
288
- "VERB|l-obl": 119,
289
- "VERB|r-acl": 120,
290
- "VERB|r-advcl": 121,
291
- "VERB|r-compound": 122,
292
- "VERB|root": 123,
293
- "X": 124,
294
- "X|l-nmod": 125,
295
- "X|r-dep": 126,
296
- "X|r-goeswith": 127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  },
298
  "layer_norm_eps": 1e-05,
299
  "local_attention": 128,
 
33
  "hidden_activation": "gelu",
34
  "hidden_size": 768,
35
  "id2label": {
36
+ "0": "ADJ|o",
37
+ "1": "ADJ|o|l-acl",
38
+ "2": "ADJ|o|l-advcl",
39
+ "3": "ADJ|o|l-amod",
40
+ "4": "ADJ|o|l-ccomp",
41
+ "5": "ADJ|o|l-csubj",
42
+ "6": "ADJ|o|l-csubj:outer",
43
+ "7": "ADJ|o|l-nmod",
44
+ "8": "ADJ|o|l-nsubj",
45
+ "9": "ADJ|o|l-obj",
46
+ "10": "ADJ|o|l-obl",
47
+ "11": "ADJ|o|r-acl",
48
+ "12": "ADJ|o|r-amod",
49
+ "13": "ADJ|o|r-dep",
50
+ "14": "ADJ|o|root",
51
+ "15": "ADJ|x",
52
+ "16": "ADJ|x|l-acl",
53
+ "17": "ADJ|x|l-advcl",
54
+ "18": "ADJ|x|l-amod",
55
+ "19": "ADJ|x|l-ccomp",
56
+ "20": "ADJ|x|l-csubj",
57
+ "21": "ADJ|x|l-csubj:outer",
58
+ "22": "ADJ|x|l-nmod",
59
+ "23": "ADJ|x|l-nsubj",
60
+ "24": "ADJ|x|l-obj",
61
+ "25": "ADJ|x|l-obl",
62
+ "26": "ADJ|x|r-acl",
63
+ "27": "ADJ|x|r-amod",
64
+ "28": "ADJ|x|r-dep",
65
+ "29": "ADJ|x|root",
66
+ "30": "ADP|o",
67
+ "31": "ADP|o|l-case",
68
+ "32": "ADP|o|r-case",
69
+ "33": "ADP|o|r-fixed",
70
+ "34": "ADP|x",
71
+ "35": "ADP|x|l-case",
72
+ "36": "ADP|x|r-case",
73
+ "37": "ADP|x|r-fixed",
74
+ "38": "ADV|o",
75
+ "39": "ADV|o|l-advcl",
76
+ "40": "ADV|o|l-advmod",
77
+ "41": "ADV|o|l-obj",
78
+ "42": "ADV|o|r-dep",
79
+ "43": "ADV|o|root",
80
+ "44": "ADV|x",
81
+ "45": "ADV|x|l-advcl",
82
+ "46": "ADV|x|l-advmod",
83
+ "47": "ADV|x|l-obj",
84
+ "48": "ADV|x|r-dep",
85
+ "49": "ADV|x|root",
86
+ "50": "AUX|o",
87
+ "51": "AUX|o|Polarity=Neg",
88
+ "52": "AUX|o|Polarity=Neg|r-aux",
89
+ "53": "AUX|o|Polarity=Neg|r-fixed",
90
+ "54": "AUX|o|r-aux",
91
+ "55": "AUX|o|r-cop",
92
+ "56": "AUX|o|r-fixed",
93
+ "57": "AUX|o|root",
94
+ "58": "AUX|x",
95
+ "59": "AUX|x|Polarity=Neg",
96
+ "60": "AUX|x|Polarity=Neg|r-aux",
97
+ "61": "AUX|x|Polarity=Neg|r-fixed",
98
+ "62": "AUX|x|r-aux",
99
+ "63": "AUX|x|r-cop",
100
+ "64": "AUX|x|r-fixed",
101
+ "65": "AUX|x|root",
102
+ "66": "CCONJ|o",
103
+ "67": "CCONJ|o|l-cc",
104
+ "68": "CCONJ|o|r-cc",
105
+ "69": "CCONJ|x",
106
+ "70": "CCONJ|x|l-cc",
107
+ "71": "CCONJ|x|r-cc",
108
+ "72": "DET|o",
109
+ "73": "DET|o|l-det",
110
+ "74": "DET|x",
111
+ "75": "DET|x|l-det",
112
+ "76": "INTJ|o",
113
+ "77": "INTJ|o|l-discourse",
114
+ "78": "INTJ|o|r-discourse",
115
+ "79": "INTJ|o|root",
116
+ "80": "INTJ|x",
117
+ "81": "INTJ|x|l-discourse",
118
+ "82": "INTJ|x|r-discourse",
119
+ "83": "INTJ|x|root",
120
+ "84": "NOUN|o",
121
+ "85": "NOUN|o|Polarity=Neg",
122
+ "86": "NOUN|o|Polarity=Neg|l-obl",
123
+ "87": "NOUN|o|Polarity=Neg|root",
124
+ "88": "NOUN|o|l-acl",
125
+ "89": "NOUN|o|l-advcl",
126
+ "90": "NOUN|o|l-ccomp",
127
+ "91": "NOUN|o|l-compound",
128
+ "92": "NOUN|o|l-csubj",
129
+ "93": "NOUN|o|l-csubj:outer",
130
+ "94": "NOUN|o|l-nmod",
131
+ "95": "NOUN|o|l-nsubj",
132
+ "96": "NOUN|o|l-nsubj:outer",
133
+ "97": "NOUN|o|l-obj",
134
+ "98": "NOUN|o|l-obl",
135
+ "99": "NOUN|o|r-compound",
136
+ "100": "NOUN|o|r-nmod",
137
+ "101": "NOUN|o|r-nsubj",
138
+ "102": "NOUN|o|root",
139
+ "103": "NOUN|x",
140
+ "104": "NOUN|x|Polarity=Neg",
141
+ "105": "NOUN|x|Polarity=Neg|l-obl",
142
+ "106": "NOUN|x|Polarity=Neg|root",
143
+ "107": "NOUN|x|l-acl",
144
+ "108": "NOUN|x|l-advcl",
145
+ "109": "NOUN|x|l-ccomp",
146
+ "110": "NOUN|x|l-compound",
147
+ "111": "NOUN|x|l-csubj",
148
+ "112": "NOUN|x|l-csubj:outer",
149
+ "113": "NOUN|x|l-nmod",
150
+ "114": "NOUN|x|l-nsubj",
151
+ "115": "NOUN|x|l-nsubj:outer",
152
+ "116": "NOUN|x|l-obj",
153
+ "117": "NOUN|x|l-obl",
154
+ "118": "NOUN|x|r-compound",
155
+ "119": "NOUN|x|r-nmod",
156
+ "120": "NOUN|x|r-nsubj",
157
+ "121": "NOUN|x|root",
158
+ "122": "NUM|o",
159
+ "123": "NUM|o|l-advcl",
160
+ "124": "NUM|o|l-compound",
161
+ "125": "NUM|o|l-nmod",
162
+ "126": "NUM|o|l-nsubj",
163
+ "127": "NUM|o|l-nsubj:outer",
164
+ "128": "NUM|o|l-nummod",
165
+ "129": "NUM|o|l-obj",
166
+ "130": "NUM|o|l-obl",
167
+ "131": "NUM|o|r-compound",
168
+ "132": "NUM|o|root",
169
+ "133": "NUM|x",
170
+ "134": "NUM|x|l-advcl",
171
+ "135": "NUM|x|l-compound",
172
+ "136": "NUM|x|l-nmod",
173
+ "137": "NUM|x|l-nsubj",
174
+ "138": "NUM|x|l-nsubj:outer",
175
+ "139": "NUM|x|l-nummod",
176
+ "140": "NUM|x|l-obj",
177
+ "141": "NUM|x|l-obl",
178
+ "142": "NUM|x|r-compound",
179
+ "143": "NUM|x|root",
180
+ "144": "PART|o",
181
+ "145": "PART|o|l-mark",
182
+ "146": "PART|o|r-mark",
183
+ "147": "PART|x",
184
+ "148": "PART|x|l-mark",
185
+ "149": "PART|x|r-mark",
186
+ "150": "PRON|o",
187
+ "151": "PRON|o|l-acl",
188
+ "152": "PRON|o|l-advcl",
189
+ "153": "PRON|o|l-nmod",
190
+ "154": "PRON|o|l-nsubj",
191
+ "155": "PRON|o|l-nsubj:outer",
192
+ "156": "PRON|o|l-obj",
193
+ "157": "PRON|o|l-obl",
194
+ "158": "PRON|o|root",
195
+ "159": "PRON|x",
196
+ "160": "PRON|x|l-acl",
197
+ "161": "PRON|x|l-advcl",
198
+ "162": "PRON|x|l-nmod",
199
+ "163": "PRON|x|l-nsubj",
200
+ "164": "PRON|x|l-nsubj:outer",
201
+ "165": "PRON|x|l-obj",
202
+ "166": "PRON|x|l-obl",
203
+ "167": "PRON|x|root",
204
+ "168": "PROPN|o",
205
+ "169": "PROPN|o|l-acl",
206
+ "170": "PROPN|o|l-advcl",
207
+ "171": "PROPN|o|l-compound",
208
+ "172": "PROPN|o|l-nmod",
209
+ "173": "PROPN|o|l-nsubj",
210
+ "174": "PROPN|o|l-nsubj:outer",
211
+ "175": "PROPN|o|l-obj",
212
+ "176": "PROPN|o|l-obl",
213
+ "177": "PROPN|o|r-compound",
214
+ "178": "PROPN|o|r-nmod",
215
+ "179": "PROPN|o|root",
216
+ "180": "PROPN|x",
217
+ "181": "PROPN|x|l-acl",
218
+ "182": "PROPN|x|l-advcl",
219
+ "183": "PROPN|x|l-compound",
220
+ "184": "PROPN|x|l-nmod",
221
+ "185": "PROPN|x|l-nsubj",
222
+ "186": "PROPN|x|l-nsubj:outer",
223
+ "187": "PROPN|x|l-obj",
224
+ "188": "PROPN|x|l-obl",
225
+ "189": "PROPN|x|r-compound",
226
+ "190": "PROPN|x|r-nmod",
227
+ "191": "PROPN|x|root",
228
+ "192": "PUNCT|o",
229
+ "193": "PUNCT|o|l-punct",
230
+ "194": "PUNCT|o|r-punct",
231
+ "195": "PUNCT|x",
232
+ "196": "PUNCT|x|l-punct",
233
+ "197": "PUNCT|x|r-punct",
234
+ "198": "SCONJ|o",
235
+ "199": "SCONJ|o|l-dep",
236
+ "200": "SCONJ|o|r-fixed",
237
+ "201": "SCONJ|o|r-mark",
238
+ "202": "SCONJ|x",
239
+ "203": "SCONJ|x|l-dep",
240
+ "204": "SCONJ|x|r-fixed",
241
+ "205": "SCONJ|x|r-mark",
242
+ "206": "SYM|o",
243
+ "207": "SYM|o|l-compound",
244
+ "208": "SYM|o|l-dep",
245
+ "209": "SYM|o|l-nmod",
246
+ "210": "SYM|o|l-obl",
247
+ "211": "SYM|o|r-compound",
248
+ "212": "SYM|o|r-dep",
249
+ "213": "SYM|x",
250
+ "214": "SYM|x|l-compound",
251
+ "215": "SYM|x|l-dep",
252
+ "216": "SYM|x|l-nmod",
253
+ "217": "SYM|x|l-obl",
254
+ "218": "SYM|x|r-compound",
255
+ "219": "SYM|x|r-dep",
256
+ "220": "VERB|o",
257
+ "221": "VERB|o|l-acl",
258
+ "222": "VERB|o|l-advcl",
259
+ "223": "VERB|o|l-ccomp",
260
+ "224": "VERB|o|l-compound",
261
+ "225": "VERB|o|l-csubj",
262
+ "226": "VERB|o|l-csubj:outer",
263
+ "227": "VERB|o|l-nmod",
264
+ "228": "VERB|o|l-obj",
265
+ "229": "VERB|o|l-obl",
266
+ "230": "VERB|o|r-acl",
267
+ "231": "VERB|o|r-advcl",
268
+ "232": "VERB|o|r-compound",
269
+ "233": "VERB|o|root",
270
+ "234": "VERB|x",
271
+ "235": "VERB|x|l-acl",
272
+ "236": "VERB|x|l-advcl",
273
+ "237": "VERB|x|l-ccomp",
274
+ "238": "VERB|x|l-compound",
275
+ "239": "VERB|x|l-csubj",
276
+ "240": "VERB|x|l-csubj:outer",
277
+ "241": "VERB|x|l-nmod",
278
+ "242": "VERB|x|l-obj",
279
+ "243": "VERB|x|l-obl",
280
+ "244": "VERB|x|r-acl",
281
+ "245": "VERB|x|r-advcl",
282
+ "246": "VERB|x|r-compound",
283
+ "247": "VERB|x|root",
284
+ "248": "X|o",
285
+ "249": "X|o|l-nmod",
286
+ "250": "X|o|r-dep",
287
+ "251": "X|x",
288
+ "252": "X|x|l-nmod",
289
+ "253": "X|x|r-dep",
290
+ "254": "X|x|r-goeswith"
291
  },
292
  "initializer_cutoff_factor": 2.0,
293
  "initializer_range": 0.02,
294
  "intermediate_size": 1152,
295
  "label2id": {
296
+ "ADJ|o": 0,
297
+ "ADJ|o|l-acl": 1,
298
+ "ADJ|o|l-advcl": 2,
299
+ "ADJ|o|l-amod": 3,
300
+ "ADJ|o|l-ccomp": 4,
301
+ "ADJ|o|l-csubj": 5,
302
+ "ADJ|o|l-csubj:outer": 6,
303
+ "ADJ|o|l-nmod": 7,
304
+ "ADJ|o|l-nsubj": 8,
305
+ "ADJ|o|l-obj": 9,
306
+ "ADJ|o|l-obl": 10,
307
+ "ADJ|o|r-acl": 11,
308
+ "ADJ|o|r-amod": 12,
309
+ "ADJ|o|r-dep": 13,
310
+ "ADJ|o|root": 14,
311
+ "ADJ|x": 15,
312
+ "ADJ|x|l-acl": 16,
313
+ "ADJ|x|l-advcl": 17,
314
+ "ADJ|x|l-amod": 18,
315
+ "ADJ|x|l-ccomp": 19,
316
+ "ADJ|x|l-csubj": 20,
317
+ "ADJ|x|l-csubj:outer": 21,
318
+ "ADJ|x|l-nmod": 22,
319
+ "ADJ|x|l-nsubj": 23,
320
+ "ADJ|x|l-obj": 24,
321
+ "ADJ|x|l-obl": 25,
322
+ "ADJ|x|r-acl": 26,
323
+ "ADJ|x|r-amod": 27,
324
+ "ADJ|x|r-dep": 28,
325
+ "ADJ|x|root": 29,
326
+ "ADP|o": 30,
327
+ "ADP|o|l-case": 31,
328
+ "ADP|o|r-case": 32,
329
+ "ADP|o|r-fixed": 33,
330
+ "ADP|x": 34,
331
+ "ADP|x|l-case": 35,
332
+ "ADP|x|r-case": 36,
333
+ "ADP|x|r-fixed": 37,
334
+ "ADV|o": 38,
335
+ "ADV|o|l-advcl": 39,
336
+ "ADV|o|l-advmod": 40,
337
+ "ADV|o|l-obj": 41,
338
+ "ADV|o|r-dep": 42,
339
+ "ADV|o|root": 43,
340
+ "ADV|x": 44,
341
+ "ADV|x|l-advcl": 45,
342
+ "ADV|x|l-advmod": 46,
343
+ "ADV|x|l-obj": 47,
344
+ "ADV|x|r-dep": 48,
345
+ "ADV|x|root": 49,
346
+ "AUX|o": 50,
347
+ "AUX|o|Polarity=Neg": 51,
348
+ "AUX|o|Polarity=Neg|r-aux": 52,
349
+ "AUX|o|Polarity=Neg|r-fixed": 53,
350
+ "AUX|o|r-aux": 54,
351
+ "AUX|o|r-cop": 55,
352
+ "AUX|o|r-fixed": 56,
353
+ "AUX|o|root": 57,
354
+ "AUX|x": 58,
355
+ "AUX|x|Polarity=Neg": 59,
356
+ "AUX|x|Polarity=Neg|r-aux": 60,
357
+ "AUX|x|Polarity=Neg|r-fixed": 61,
358
+ "AUX|x|r-aux": 62,
359
+ "AUX|x|r-cop": 63,
360
+ "AUX|x|r-fixed": 64,
361
+ "AUX|x|root": 65,
362
+ "CCONJ|o": 66,
363
+ "CCONJ|o|l-cc": 67,
364
+ "CCONJ|o|r-cc": 68,
365
+ "CCONJ|x": 69,
366
+ "CCONJ|x|l-cc": 70,
367
+ "CCONJ|x|r-cc": 71,
368
+ "DET|o": 72,
369
+ "DET|o|l-det": 73,
370
+ "DET|x": 74,
371
+ "DET|x|l-det": 75,
372
+ "INTJ|o": 76,
373
+ "INTJ|o|l-discourse": 77,
374
+ "INTJ|o|r-discourse": 78,
375
+ "INTJ|o|root": 79,
376
+ "INTJ|x": 80,
377
+ "INTJ|x|l-discourse": 81,
378
+ "INTJ|x|r-discourse": 82,
379
+ "INTJ|x|root": 83,
380
+ "NOUN|o": 84,
381
+ "NOUN|o|Polarity=Neg": 85,
382
+ "NOUN|o|Polarity=Neg|l-obl": 86,
383
+ "NOUN|o|Polarity=Neg|root": 87,
384
+ "NOUN|o|l-acl": 88,
385
+ "NOUN|o|l-advcl": 89,
386
+ "NOUN|o|l-ccomp": 90,
387
+ "NOUN|o|l-compound": 91,
388
+ "NOUN|o|l-csubj": 92,
389
+ "NOUN|o|l-csubj:outer": 93,
390
+ "NOUN|o|l-nmod": 94,
391
+ "NOUN|o|l-nsubj": 95,
392
+ "NOUN|o|l-nsubj:outer": 96,
393
+ "NOUN|o|l-obj": 97,
394
+ "NOUN|o|l-obl": 98,
395
+ "NOUN|o|r-compound": 99,
396
+ "NOUN|o|r-nmod": 100,
397
+ "NOUN|o|r-nsubj": 101,
398
+ "NOUN|o|root": 102,
399
+ "NOUN|x": 103,
400
+ "NOUN|x|Polarity=Neg": 104,
401
+ "NOUN|x|Polarity=Neg|l-obl": 105,
402
+ "NOUN|x|Polarity=Neg|root": 106,
403
+ "NOUN|x|l-acl": 107,
404
+ "NOUN|x|l-advcl": 108,
405
+ "NOUN|x|l-ccomp": 109,
406
+ "NOUN|x|l-compound": 110,
407
+ "NOUN|x|l-csubj": 111,
408
+ "NOUN|x|l-csubj:outer": 112,
409
+ "NOUN|x|l-nmod": 113,
410
+ "NOUN|x|l-nsubj": 114,
411
+ "NOUN|x|l-nsubj:outer": 115,
412
+ "NOUN|x|l-obj": 116,
413
+ "NOUN|x|l-obl": 117,
414
+ "NOUN|x|r-compound": 118,
415
+ "NOUN|x|r-nmod": 119,
416
+ "NOUN|x|r-nsubj": 120,
417
+ "NOUN|x|root": 121,
418
+ "NUM|o": 122,
419
+ "NUM|o|l-advcl": 123,
420
+ "NUM|o|l-compound": 124,
421
+ "NUM|o|l-nmod": 125,
422
+ "NUM|o|l-nsubj": 126,
423
+ "NUM|o|l-nsubj:outer": 127,
424
+ "NUM|o|l-nummod": 128,
425
+ "NUM|o|l-obj": 129,
426
+ "NUM|o|l-obl": 130,
427
+ "NUM|o|r-compound": 131,
428
+ "NUM|o|root": 132,
429
+ "NUM|x": 133,
430
+ "NUM|x|l-advcl": 134,
431
+ "NUM|x|l-compound": 135,
432
+ "NUM|x|l-nmod": 136,
433
+ "NUM|x|l-nsubj": 137,
434
+ "NUM|x|l-nsubj:outer": 138,
435
+ "NUM|x|l-nummod": 139,
436
+ "NUM|x|l-obj": 140,
437
+ "NUM|x|l-obl": 141,
438
+ "NUM|x|r-compound": 142,
439
+ "NUM|x|root": 143,
440
+ "PART|o": 144,
441
+ "PART|o|l-mark": 145,
442
+ "PART|o|r-mark": 146,
443
+ "PART|x": 147,
444
+ "PART|x|l-mark": 148,
445
+ "PART|x|r-mark": 149,
446
+ "PRON|o": 150,
447
+ "PRON|o|l-acl": 151,
448
+ "PRON|o|l-advcl": 152,
449
+ "PRON|o|l-nmod": 153,
450
+ "PRON|o|l-nsubj": 154,
451
+ "PRON|o|l-nsubj:outer": 155,
452
+ "PRON|o|l-obj": 156,
453
+ "PRON|o|l-obl": 157,
454
+ "PRON|o|root": 158,
455
+ "PRON|x": 159,
456
+ "PRON|x|l-acl": 160,
457
+ "PRON|x|l-advcl": 161,
458
+ "PRON|x|l-nmod": 162,
459
+ "PRON|x|l-nsubj": 163,
460
+ "PRON|x|l-nsubj:outer": 164,
461
+ "PRON|x|l-obj": 165,
462
+ "PRON|x|l-obl": 166,
463
+ "PRON|x|root": 167,
464
+ "PROPN|o": 168,
465
+ "PROPN|o|l-acl": 169,
466
+ "PROPN|o|l-advcl": 170,
467
+ "PROPN|o|l-compound": 171,
468
+ "PROPN|o|l-nmod": 172,
469
+ "PROPN|o|l-nsubj": 173,
470
+ "PROPN|o|l-nsubj:outer": 174,
471
+ "PROPN|o|l-obj": 175,
472
+ "PROPN|o|l-obl": 176,
473
+ "PROPN|o|r-compound": 177,
474
+ "PROPN|o|r-nmod": 178,
475
+ "PROPN|o|root": 179,
476
+ "PROPN|x": 180,
477
+ "PROPN|x|l-acl": 181,
478
+ "PROPN|x|l-advcl": 182,
479
+ "PROPN|x|l-compound": 183,
480
+ "PROPN|x|l-nmod": 184,
481
+ "PROPN|x|l-nsubj": 185,
482
+ "PROPN|x|l-nsubj:outer": 186,
483
+ "PROPN|x|l-obj": 187,
484
+ "PROPN|x|l-obl": 188,
485
+ "PROPN|x|r-compound": 189,
486
+ "PROPN|x|r-nmod": 190,
487
+ "PROPN|x|root": 191,
488
+ "PUNCT|o": 192,
489
+ "PUNCT|o|l-punct": 193,
490
+ "PUNCT|o|r-punct": 194,
491
+ "PUNCT|x": 195,
492
+ "PUNCT|x|l-punct": 196,
493
+ "PUNCT|x|r-punct": 197,
494
+ "SCONJ|o": 198,
495
+ "SCONJ|o|l-dep": 199,
496
+ "SCONJ|o|r-fixed": 200,
497
+ "SCONJ|o|r-mark": 201,
498
+ "SCONJ|x": 202,
499
+ "SCONJ|x|l-dep": 203,
500
+ "SCONJ|x|r-fixed": 204,
501
+ "SCONJ|x|r-mark": 205,
502
+ "SYM|o": 206,
503
+ "SYM|o|l-compound": 207,
504
+ "SYM|o|l-dep": 208,
505
+ "SYM|o|l-nmod": 209,
506
+ "SYM|o|l-obl": 210,
507
+ "SYM|o|r-compound": 211,
508
+ "SYM|o|r-dep": 212,
509
+ "SYM|x": 213,
510
+ "SYM|x|l-compound": 214,
511
+ "SYM|x|l-dep": 215,
512
+ "SYM|x|l-nmod": 216,
513
+ "SYM|x|l-obl": 217,
514
+ "SYM|x|r-compound": 218,
515
+ "SYM|x|r-dep": 219,
516
+ "VERB|o": 220,
517
+ "VERB|o|l-acl": 221,
518
+ "VERB|o|l-advcl": 222,
519
+ "VERB|o|l-ccomp": 223,
520
+ "VERB|o|l-compound": 224,
521
+ "VERB|o|l-csubj": 225,
522
+ "VERB|o|l-csubj:outer": 226,
523
+ "VERB|o|l-nmod": 227,
524
+ "VERB|o|l-obj": 228,
525
+ "VERB|o|l-obl": 229,
526
+ "VERB|o|r-acl": 230,
527
+ "VERB|o|r-advcl": 231,
528
+ "VERB|o|r-compound": 232,
529
+ "VERB|o|root": 233,
530
+ "VERB|x": 234,
531
+ "VERB|x|l-acl": 235,
532
+ "VERB|x|l-advcl": 236,
533
+ "VERB|x|l-ccomp": 237,
534
+ "VERB|x|l-compound": 238,
535
+ "VERB|x|l-csubj": 239,
536
+ "VERB|x|l-csubj:outer": 240,
537
+ "VERB|x|l-nmod": 241,
538
+ "VERB|x|l-obj": 242,
539
+ "VERB|x|l-obl": 243,
540
+ "VERB|x|r-acl": 244,
541
+ "VERB|x|r-advcl": 245,
542
+ "VERB|x|r-compound": 246,
543
+ "VERB|x|root": 247,
544
+ "X|o": 248,
545
+ "X|o|l-nmod": 249,
546
+ "X|o|r-dep": 250,
547
+ "X|x": 251,
548
+ "X|x|l-nmod": 252,
549
+ "X|x|r-dep": 253,
550
+ "X|x|r-goeswith": 254
551
  },
552
  "layer_norm_eps": 1e-05,
553
  "local_attention": 128,
maker.py CHANGED
@@ -7,12 +7,12 @@ d=os.path.basename(url)
7
  os.system("test -d "+d+" || git clone --depth=1 "+url)
8
  os.system("for F in train dev test ; do cp "+d+"/*-$F.conllu $F.conllu ; done")
9
  class UDTriangularDataset(object):
10
- def __init__(self,conllu,tokenizer,embeddings=None):
11
  self.conllu=open(conllu,"r",encoding="utf-8")
12
  self.tokenizer=tokenizer
13
  self.seeks=[0]
14
- label=set(["SYM","X"])
15
- dep=set(["X|r-goeswith"])
16
  s=self.conllu.readline()
17
  while s!="":
18
  if s=="\n":
@@ -21,9 +21,13 @@ class UDTriangularDataset(object):
21
  w=s.split("\t")
22
  if len(w)==10:
23
  if w[0].isdecimal():
24
- p=w[3] if w[5]=="_" else w[3]+"|"+w[5]
25
- label.add(p)
26
- dep.add(p+("|" if w[6]=="0" else "|l-" if int(w[0])<int(w[6]) else "|r-")+w[7])
 
 
 
 
27
  s=self.conllu.readline()
28
  lid={l:i for i,l in enumerate(sorted(label))}
29
  for i,d in enumerate(sorted(dep),len(lid)):
@@ -51,19 +55,27 @@ class UDTriangularDataset(object):
51
  c.insert(i+1,[c[i][0],"_","_","X","_","_",c[i][0],"goeswith","_","_"])
52
  y=["0"]+[t[0] for t in c]
53
  h=[i if t[6]=="0" else y.index(t[6]) for i,t in enumerate(c,1)]
54
- p=[t[3] if t[5]=="_" else t[3]+"|"+t[5] for t in c]
 
 
 
 
 
 
 
55
  d=[t[7] if t[6]=="0" else "l-"+t[7] if int(t[0])<int(t[6]) else "r-"+t[7] for t in c]
56
  v=sum(v,[])
57
  ids=[self.tokenizer.cls_token_id]
58
- upos=["SYM"]
59
  for i,k in enumerate(v):
60
- ids.append(k)
61
- upos.append(p[i]+"|"+d[i] if h[i]==i+1 else p[i])
62
- for j in range(i+1,len(v)):
63
- ids.append(v[j])
64
- upos.append(p[j]+"|"+d[j] if h[j]==i+1 else p[i]+"|"+d[i] if h[i]==j+1 else p[j])
65
- ids.append(self.tokenizer.sep_token_id)
66
- upos.append("SYM")
 
67
  return {"input_ids":ids,"labels":[self.label2id[p] for p in upos]}
68
  from transformers import AutoTokenizer,AutoConfig,AutoModelForTokenClassification,DataCollatorForTokenClassification,TrainingArguments,Trainer
69
  tkz=AutoTokenizer.from_pretrained(src)
 
7
  os.system("test -d "+d+" || git clone --depth=1 "+url)
8
  os.system("for F in train dev test ; do cp "+d+"/*-$F.conllu $F.conllu ; done")
9
  class UDTriangularDataset(object):
10
+ def __init__(self,conllu,tokenizer):
11
  self.conllu=open(conllu,"r",encoding="utf-8")
12
  self.tokenizer=tokenizer
13
  self.seeks=[0]
14
+ label=set(["SYM|x","X|x"])
15
+ dep=set(["X|x|r-goeswith"])
16
  s=self.conllu.readline()
17
  while s!="":
18
  if s=="\n":
 
21
  w=s.split("\t")
22
  if len(w)==10:
23
  if w[0].isdecimal():
24
+ p=w[3]
25
+ q="" if w[5]=="_" else "|"+w[5]
26
+ d=("|" if w[6]=="0" else "|l-" if int(w[0])<int(w[6]) else "|r-")+w[7]
27
+ label.add(p+"|o"+q)
28
+ label.add(p+"|x"+q)
29
+ dep.add(p+"|o"+q+d)
30
+ dep.add(p+"|x"+q+d)
31
  s=self.conllu.readline()
32
  lid={l:i for i,l in enumerate(sorted(label))}
33
  for i,d in enumerate(sorted(dep),len(lid)):
 
55
  c.insert(i+1,[c[i][0],"_","_","X","_","_",c[i][0],"goeswith","_","_"])
56
  y=["0"]+[t[0] for t in c]
57
  h=[i if t[6]=="0" else y.index(t[6]) for i,t in enumerate(c,1)]
58
+ x=["o" if k>i or sum([1 if j==i+1 else 0 for j in h[i+1:]])>0 else "x" for i,k in enumerate(h)]
59
+ z=[len(x)-i+1 if k=="o" else 0 for i,k in enumerate(x)]
60
+ w=sum(z)+1
61
+ for i,j in enumerate(z):
62
+ if j==0 and w+len(x)-i<8192:
63
+ z[i]=len(x)-i+1
64
+ w+=z[i]
65
+ p=[t[3]+"|"+x[i] if t[5]=="_" else t[3]+"|"+x[i]+"|"+t[5] for i,t in enumerate(c)]
66
  d=[t[7] if t[6]=="0" else "l-"+t[7] if int(t[0])<int(t[6]) else "r-"+t[7] for t in c]
67
  v=sum(v,[])
68
  ids=[self.tokenizer.cls_token_id]
69
+ upos=["SYM|x"]
70
  for i,k in enumerate(v):
71
+ if z[i]>0:
72
+ ids.append(k)
73
+ upos.append(p[i]+"|"+d[i] if h[i]==i+1 else p[i])
74
+ for j in range(i+1,len(v)):
75
+ ids.append(v[j])
76
+ upos.append(p[j]+"|"+d[j] if h[j]==i+1 else p[i]+"|"+d[i] if h[i]==j+1 else p[j])
77
+ ids.append(self.tokenizer.sep_token_id)
78
+ upos.append("SYM|x")
79
  return {"input_ids":ids,"labels":[self.label2id[p] for p in upos]}
80
  from transformers import AutoTokenizer,AutoConfig,AutoModelForTokenClassification,DataCollatorForTokenClassification,TrainingArguments,Trainer
81
  tkz=AutoTokenizer.from_pretrained(src)
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:0150e7519d7c382222f5dc38320b305f3eed53f6cf737c9233ba964521c3cfdf
3
- size 643808050
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:972383c5654a11a5ff63bf765edf9fbfecaff7769b24eeb85249895d185d2ed7
3
+ size 644198706
ud.py CHANGED
@@ -5,9 +5,9 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
5
  def __init__(self,**kwargs):
6
  super().__init__(**kwargs)
7
  x=self.model.config.label2id
8
- self.root=numpy.full((len(x)),numpy.nan)
9
- self.left_arc=numpy.full((len(x)),numpy.nan)
10
- self.right_arc=numpy.full((len(x)),numpy.nan)
11
  for k,v in x.items():
12
  if k.endswith("|root"):
13
  self.root[v]=0
@@ -15,41 +15,73 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
15
  self.left_arc[v]=0
16
  elif k.find("|r-")>0:
17
  self.right_arc[v]=0
18
- def _forward(self,model_inputs):
19
- import torch
20
- v=model_inputs["input_ids"][0].tolist()
21
- with torch.no_grad():
22
- e=self.model(input_ids=torch.tensor([sum([v]+[v[i:] for i in range(2,len(v)-1)],[])]).to(self.device))
23
- return {"logits":e.logits,**model_inputs}
24
  def check_model_type(self,supported_models):
25
  pass
26
  def postprocess(self,model_outputs,**kwargs):
 
27
  if "logits" not in model_outputs:
28
  return "".join(self.postprocess(x,**kwargs) for x in model_outputs)
29
  m=model_outputs["logits"][0].cpu().numpy()
30
- w=len(model_outputs["input_ids"][0])-2
31
- e=numpy.zeros((w,w,m.shape[-1]))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  k=1
33
  for i in range(w):
34
- e[i,i]=m[k]+self.root
35
- for j in range(1,w-i):
36
- e[i+j,i]=m[k+j]+self.left_arc
37
- e[i,i+j]=m[k+j]+self.right_arc
38
- k+=w-i+1
39
- g=self.model.config.label2id["X|r-goeswith"]
 
 
 
40
  r=numpy.tri(e.shape[0])
41
  for i in range(e.shape[0]):
42
  for j in range(i+2,e.shape[1]):
43
- r[i,j]=r[i,j-1] if numpy.nanargmax(e[i,j-1])==g else 1
44
- e[:,:,g]+=numpy.where(r==0,0,numpy.nan)
45
- m,p=numpy.nanmax(e,axis=2),numpy.nanargmax(e,axis=2)
46
  h=self.chu_liu_edmonds(m)
47
  z=[i for i,j in enumerate(h) if i==j]
48
  if len(z)>1:
49
- k,h=z[numpy.nanargmax(m[z,z])],numpy.nanmin(m)-numpy.nanmax(m)
50
  m[:,z]+=[[0 if j in z and (i!=j or i==k) else h for i in z] for j in range(m.shape[0])]
51
  h=self.chu_liu_edmonds(m)
52
- v=[(s,e) for s,e in model_outputs["offset_mapping"][0].tolist() if s<e]
53
  q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
54
  if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
55
  for i,j in reversed(list(enumerate(q[1:],1))):
@@ -64,11 +96,10 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
64
  t=model_outputs["sentence"].replace("\n"," ")
65
  u="# text = "+t+"\n"
66
  for i,(s,e) in enumerate(v):
67
- u+="\t".join([str(i+1),t[s:e],"_",q[i][0],"_","_" if len(q[i])<3 else "|".join(q[i][1:-1]),str(0 if h[i]==i else h[i]+1),"root" if q[i][-1]=="root" else q[i][-1][2:],"_","_" if i+1<len(v) and e<v[i+1][0] else "SpaceAfter=No"])+"\n"
68
  return u+"\n"
69
  def chu_liu_edmonds(self,matrix):
70
- import numpy
71
- h=numpy.nanargmax(matrix,axis=0)
72
  x=[-1 if i==j else j for i,j in enumerate(h)]
73
  for b in [lambda x,i,j:-1 if i not in x else x[i],lambda x,i,j:-1 if j<0 else x[j]]:
74
  y=[]
@@ -79,10 +110,10 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
79
  if max(x)<0:
80
  return h
81
  y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
82
- z=matrix-numpy.nanmax(matrix,axis=0)
83
- m=numpy.block([[z[x,:][:,x],numpy.nanmax(z[x,:][:,y],axis=1).reshape(len(x),1)],[numpy.nanmax(z[y,:][:,x],axis=0),numpy.nanmax(z[y,y])]])
84
- k=[j if i==len(x) else x[j] if j<len(x) else y[numpy.nanargmax(z[y,x[i]])] for i,j in enumerate(self.chu_liu_edmonds(m))]
85
  h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
86
- i=y[numpy.nanargmax(z[x[k[-1]],y] if k[-1]<len(x) else z[y,y])]
87
  h[i]=x[k[-1]] if k[-1]<len(x) else i
88
  return h
 
5
  def __init__(self,**kwargs):
6
  super().__init__(**kwargs)
7
  x=self.model.config.label2id
8
+ self.root=numpy.full((len(x)),-numpy.inf)
9
+ self.left_arc=numpy.full((len(x)),-numpy.inf)
10
+ self.right_arc=numpy.full((len(x)),-numpy.inf)
11
  for k,v in x.items():
12
  if k.endswith("|root"):
13
  self.root[v]=0
 
15
  self.left_arc[v]=0
16
  elif k.find("|r-")>0:
17
  self.right_arc[v]=0
 
 
 
 
 
 
18
  def check_model_type(self,supported_models):
19
  pass
20
  def postprocess(self,model_outputs,**kwargs):
21
+ import torch
22
  if "logits" not in model_outputs:
23
  return "".join(self.postprocess(x,**kwargs) for x in model_outputs)
24
  m=model_outputs["logits"][0].cpu().numpy()
25
+ k=numpy.argmax(m,axis=1).tolist()
26
+ x=[self.model.config.id2label[i].split("|")[1]=="o" for i in k[1:-1]]
27
+ v=model_outputs["input_ids"][0].tolist()
28
+ off=model_outputs["offset_mapping"][0].tolist()
29
+ for i,(s,e) in reversed(list(enumerate(off))):
30
+ if s<e:
31
+ d=model_outputs["sentence"][s:e]
32
+ j=len(d)-len(d.lstrip())
33
+ if j>0:
34
+ d=d.lstrip()
35
+ off[i][0]+=j
36
+ j=len(d)-len(d.rstrip())
37
+ if j>0:
38
+ d=d.rstrip()
39
+ off[i][1]-=j
40
+ if d.strip()=="":
41
+ off.pop(i)
42
+ v.pop(i)
43
+ x.pop(i-1)
44
+ if len(x)<127:
45
+ x=[True]*len(x)
46
+ else:
47
+ w=sum([len(x)-i+1 if b else 0 for i,b in enumerate(x)])+1
48
+ for i in numpy.argsort(numpy.max(m,axis=1)[1:-1]):
49
+ if x[i]==False and w+len(x)-i<8192:
50
+ x[i]=True
51
+ w+=len(x)-i+1
52
+ w=[self.tokenizer.cls_token_id]
53
+ for i,j in enumerate(x):
54
+ if j:
55
+ w+=v[i+1:]
56
+ with torch.no_grad():
57
+ e=self.model(input_ids=torch.tensor([w]).to(self.device))
58
+ m=e.logits[0].cpu().numpy()
59
+ w=len(v)-2
60
+ e=numpy.full((w,w,m.shape[-1]),m.min())
61
  k=1
62
  for i in range(w):
63
+ if x[i]:
64
+ e[i,i]=m[k]+self.root
65
+ k+=1
66
+ for j in range(1,w-i):
67
+ e[i+j,i]=m[k]+self.left_arc
68
+ e[i,i+j]=m[k]+self.right_arc
69
+ k+=1
70
+ k+=1
71
+ g=self.model.config.label2id["X|x|r-goeswith"]
72
  r=numpy.tri(e.shape[0])
73
  for i in range(e.shape[0]):
74
  for j in range(i+2,e.shape[1]):
75
+ r[i,j]=r[i,j-1] if numpy.argmax(e[i,j-1])==g else 1
76
+ e[:,:,g]+=numpy.where(r==0,0,-numpy.inf)
77
+ m,p=numpy.max(e,axis=2),numpy.argmax(e,axis=2)
78
  h=self.chu_liu_edmonds(m)
79
  z=[i for i,j in enumerate(h) if i==j]
80
  if len(z)>1:
81
+ k,h=z[numpy.argmax(m[z,z])],numpy.min(m)-numpy.max(m)
82
  m[:,z]+=[[0 if j in z and (i!=j or i==k) else h for i in z] for j in range(m.shape[0])]
83
  h=self.chu_liu_edmonds(m)
84
+ v=[(s,e) for s,e in off if s<e]
85
  q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
86
  if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
87
  for i,j in reversed(list(enumerate(q[1:],1))):
 
96
  t=model_outputs["sentence"].replace("\n"," ")
97
  u="# text = "+t+"\n"
98
  for i,(s,e) in enumerate(v):
99
+ u+="\t".join([str(i+1),t[s:e],"_",q[i][0],"_","_" if len(q[i])<4 else "|".join(q[i][2:-1]),str(0 if h[i]==i else h[i]+1),"root" if q[i][-1]=="root" else q[i][-1][2:],"_","_" if i+1<len(v) and e<v[i+1][0] else "SpaceAfter=No"])+"\n"
100
  return u+"\n"
101
  def chu_liu_edmonds(self,matrix):
102
+ h=numpy.argmax(matrix,axis=0)
 
103
  x=[-1 if i==j else j for i,j in enumerate(h)]
104
  for b in [lambda x,i,j:-1 if i not in x else x[i],lambda x,i,j:-1 if j<0 else x[j]]:
105
  y=[]
 
110
  if max(x)<0:
111
  return h
112
  y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
113
+ z=matrix-numpy.max(matrix,axis=0)
114
+ m=numpy.block([[z[x,:][:,x],numpy.max(z[x,:][:,y],axis=1).reshape(len(x),1)],[numpy.max(z[y,:][:,x],axis=0),numpy.max(z[y,y])]])
115
+ k=[j if i==len(x) else x[j] if j<len(x) else y[numpy.argmax(z[y,x[i]])] for i,j in enumerate(self.chu_liu_edmonds(m))]
116
  h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
117
+ i=y[numpy.argmax(z[x[k[-1]],y] if k[-1]<len(x) else z[y,y])]
118
  h[i]=x[k[-1]] if k[-1]<len(x) else i
119
  return h