KoichiYasuoka commited on
Commit
52db912
·
1 Parent(s): bc4cc6c

initial release

Browse files
Files changed (9) hide show
  1. README.md +29 -0
  2. config.json +0 -0
  3. maker.py +63 -0
  4. pytorch_model.bin +3 -0
  5. special_tokens_map.json +51 -0
  6. tokenizer.json +0 -0
  7. tokenizer.model +3 -0
  8. tokenizer_config.json +318 -0
  9. ud.py +81 -0
README.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - "uk"
4
+ tags:
5
+ - "ukrainian"
6
+ - "token-classification"
7
+ - "pos"
8
+ - "dependency-parsing"
9
+ base_model: Goader/liberta-large-v2
10
+ datasets:
11
+ - "universal_dependencies"
12
+ license: "cc-by-4.0"
13
+ pipeline_tag: "token-classification"
14
+ ---
15
+
16
+ # bert-large-ukrainian-ud-goeswith
17
+
18
+ ## Model Description
19
+
20
+ This is a BERT model for POS-tagging and dependency-parsing (using `goeswith` for subwords), derived from [liberta-large-v2](https://huggingface.co/Goader/liberta-large-v2).
21
+
22
+ ## How to Use
23
+
24
+ ```py
25
+ from transformers import pipeline
26
+ nlp=pipeline("universal-dependencies","KoichiYasuoka/bert-large-ukrainian-ud-goeswith",trust_remote_code=True,aggregation_strategy="simple")
27
+ print(nlp("Біжать алеї звуків, саджених у гами."))
28
+ ```
29
+
config.json ADDED
The diff for this file is too large to render. See raw diff
 
maker.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /usr/bin/python3
2
+ src="Goader/liberta-large-v2"
3
+ tgt="KoichiYasuoka/bert-large-ukrainian-ud-goeswith"
4
+ url="https://github.com/UniversalDependencies/UD_Ukrainian-"
5
+ import os
6
+ for e in ["IU","ParlaMint"]:
7
+ u=url+e
8
+ d=os.path.basename(u)
9
+ os.system("test -d "+d+" || git clone --depth=1 "+u)
10
+ os.system("for F in train dev test ; do cat UD_Ukrainian-*/*-$F.conllu > $F.conllu ; done")
11
+ class UDgoeswithDataset(object):
12
+ def __init__(self,conllu,tokenizer):
13
+ self.ids,self.tags,label=[],[],set()
14
+ with open(conllu,"r",encoding="utf-8") as r:
15
+ cls,sep,msk=tokenizer.cls_token_id,tokenizer.sep_token_id,tokenizer.mask_token_id
16
+ dep,c,m="-|_|dep",[],False
17
+ for s in r:
18
+ t=s.split("\t")
19
+ if len(t)==10:
20
+ if t[0].isdecimal():
21
+ i=int(t[0])
22
+ if m:
23
+ t[1]=" "+t[1]
24
+ c.append(t)
25
+ m=t[9].find("SpaceAfter=No")<0
26
+ elif c!=[]:
27
+ v=tokenizer([t[1] for t in c],add_special_tokens=False)["input_ids"]
28
+ for i in range(len(v)-1,-1,-1):
29
+ for j in range(1,len(v[i])):
30
+ c.insert(i+1,[c[i][0],"_","_","X","_","_",c[i][0],"goeswith","_","_"])
31
+ y=["0"]+[t[0] for t in c]
32
+ h=[i if t[6]=="0" else y.index(t[6]) for i,t in enumerate(c,1)]
33
+ p,v=[t[3]+"|"+t[5]+"|"+t[7] for t in c],sum(v,[])
34
+ if len(v)<tokenizer.model_max_length-3:
35
+ self.ids.append([cls]+v+[sep])
36
+ self.tags.append([dep]+p+[dep])
37
+ label=set(sum([self.tags[-1],list(label)],[]))
38
+ for i,k in enumerate(v):
39
+ self.ids.append([cls]+v[0:i]+[msk]+v[i+1:]+[sep,k])
40
+ self.tags.append([dep]+[t if h[j]==i+1 else dep for j,t in enumerate(p)]+[dep,dep])
41
+ c,m=[],False
42
+ self.label2id={l:i for i,l in enumerate(sorted(label))}
43
+ def __call__(*args):
44
+ label=set(sum([list(t.label2id) for t in args],[]))
45
+ lid={l:i for i,l in enumerate(sorted(label))}
46
+ for t in args:
47
+ t.label2id=lid
48
+ return lid
49
+ __len__=lambda self:len(self.ids)
50
+ __getitem__=lambda self,i:{"input_ids":self.ids[i],"labels":[self.label2id[t] for t in self.tags[i]]}
51
+ from transformers import LlamaTokenizerFast,AutoConfig,AutoModelForTokenClassification,DataCollatorForTokenClassification,TrainingArguments,Trainer
52
+ from transformers.utils import cached_file
53
+ tkz=LlamaTokenizerFast.from_pretrained(src,vocab_file=cached_file(src,"spm.model"),bos_token="<cls>",eos_token="<sep>",add_bos_token=True,add_eos_token=True,add_prefix_space=False)
54
+ trainDS=UDgoeswithDataset("train.conllu",tkz)
55
+ devDS=UDgoeswithDataset("dev.conllu",tkz)
56
+ testDS=UDgoeswithDataset("test.conllu",tkz)
57
+ lid=trainDS(devDS,testDS)
58
+ cfg=AutoConfig.from_pretrained(src,num_labels=len(lid),label2id=lid,id2label={i:l for l,i in lid.items()})
59
+ arg=TrainingArguments(num_train_epochs=3,per_device_train_batch_size=8,output_dir=tgt,overwrite_output_dir=True,save_total_limit=2,eval_strategy="epoch",learning_rate=5e-05,warmup_ratio=0.1,save_safetensors=False)
60
+ trn=Trainer(args=arg,data_collator=DataCollatorForTokenClassification(tkz),model=AutoModelForTokenClassification.from_pretrained(src,config=cfg),train_dataset=trainDS,eval_dataset=devDS)
61
+ trn.train()
62
+ trn.save_model(tgt)
63
+ tkz.save_pretrained(tgt)
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:715bb050c6d04204694d1548fea8798644fed701dabaa028e0bc3eb67a8e181a
3
+ size 1496950054
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<cls>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<cls>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "<sep>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": true,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "<sep>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c9699b255aa5ddd6575f1f3834454778153ebb60f957ac139d7b1685865e5e7
3
+ size 2404944
tokenizer_config.json ADDED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": true,
4
+ "add_prefix_space": false,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<pad>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<unk>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "<cls>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "3": {
31
+ "content": "<sep>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "4": {
39
+ "content": "<mask>",
40
+ "lstrip": true,
41
+ "normalized": true,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "5": {
47
+ "content": "!",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": false,
51
+ "single_word": false,
52
+ "special": false
53
+ },
54
+ "6": {
55
+ "content": "\"",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false,
60
+ "special": false
61
+ },
62
+ "7": {
63
+ "content": "#",
64
+ "lstrip": false,
65
+ "normalized": false,
66
+ "rstrip": false,
67
+ "single_word": false,
68
+ "special": false
69
+ },
70
+ "8": {
71
+ "content": "$",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": false,
75
+ "single_word": false,
76
+ "special": false
77
+ },
78
+ "9": {
79
+ "content": "%",
80
+ "lstrip": false,
81
+ "normalized": false,
82
+ "rstrip": false,
83
+ "single_word": false,
84
+ "special": false
85
+ },
86
+ "10": {
87
+ "content": "&",
88
+ "lstrip": false,
89
+ "normalized": false,
90
+ "rstrip": false,
91
+ "single_word": false,
92
+ "special": false
93
+ },
94
+ "11": {
95
+ "content": "'",
96
+ "lstrip": false,
97
+ "normalized": false,
98
+ "rstrip": false,
99
+ "single_word": false,
100
+ "special": false
101
+ },
102
+ "12": {
103
+ "content": "(",
104
+ "lstrip": false,
105
+ "normalized": false,
106
+ "rstrip": false,
107
+ "single_word": false,
108
+ "special": false
109
+ },
110
+ "13": {
111
+ "content": ")",
112
+ "lstrip": false,
113
+ "normalized": false,
114
+ "rstrip": false,
115
+ "single_word": false,
116
+ "special": false
117
+ },
118
+ "14": {
119
+ "content": "*",
120
+ "lstrip": false,
121
+ "normalized": false,
122
+ "rstrip": false,
123
+ "single_word": false,
124
+ "special": false
125
+ },
126
+ "15": {
127
+ "content": "+",
128
+ "lstrip": false,
129
+ "normalized": false,
130
+ "rstrip": false,
131
+ "single_word": false,
132
+ "special": false
133
+ },
134
+ "16": {
135
+ "content": ",",
136
+ "lstrip": false,
137
+ "normalized": false,
138
+ "rstrip": false,
139
+ "single_word": false,
140
+ "special": false
141
+ },
142
+ "17": {
143
+ "content": "-",
144
+ "lstrip": false,
145
+ "normalized": false,
146
+ "rstrip": false,
147
+ "single_word": false,
148
+ "special": false
149
+ },
150
+ "18": {
151
+ "content": ".",
152
+ "lstrip": false,
153
+ "normalized": false,
154
+ "rstrip": false,
155
+ "single_word": false,
156
+ "special": false
157
+ },
158
+ "19": {
159
+ "content": "/",
160
+ "lstrip": false,
161
+ "normalized": false,
162
+ "rstrip": false,
163
+ "single_word": false,
164
+ "special": false
165
+ },
166
+ "20": {
167
+ "content": ":",
168
+ "lstrip": false,
169
+ "normalized": false,
170
+ "rstrip": false,
171
+ "single_word": false,
172
+ "special": false
173
+ },
174
+ "21": {
175
+ "content": ";",
176
+ "lstrip": false,
177
+ "normalized": false,
178
+ "rstrip": false,
179
+ "single_word": false,
180
+ "special": false
181
+ },
182
+ "22": {
183
+ "content": "<",
184
+ "lstrip": false,
185
+ "normalized": false,
186
+ "rstrip": false,
187
+ "single_word": false,
188
+ "special": false
189
+ },
190
+ "23": {
191
+ "content": "=",
192
+ "lstrip": false,
193
+ "normalized": false,
194
+ "rstrip": false,
195
+ "single_word": false,
196
+ "special": false
197
+ },
198
+ "24": {
199
+ "content": ">",
200
+ "lstrip": false,
201
+ "normalized": false,
202
+ "rstrip": false,
203
+ "single_word": false,
204
+ "special": false
205
+ },
206
+ "25": {
207
+ "content": "?",
208
+ "lstrip": false,
209
+ "normalized": false,
210
+ "rstrip": false,
211
+ "single_word": false,
212
+ "special": false
213
+ },
214
+ "26": {
215
+ "content": "@",
216
+ "lstrip": false,
217
+ "normalized": false,
218
+ "rstrip": false,
219
+ "single_word": false,
220
+ "special": false
221
+ },
222
+ "27": {
223
+ "content": "[",
224
+ "lstrip": false,
225
+ "normalized": false,
226
+ "rstrip": false,
227
+ "single_word": false,
228
+ "special": false
229
+ },
230
+ "28": {
231
+ "content": "\\",
232
+ "lstrip": false,
233
+ "normalized": false,
234
+ "rstrip": false,
235
+ "single_word": false,
236
+ "special": false
237
+ },
238
+ "29": {
239
+ "content": "]",
240
+ "lstrip": false,
241
+ "normalized": false,
242
+ "rstrip": false,
243
+ "single_word": false,
244
+ "special": false
245
+ },
246
+ "30": {
247
+ "content": "^",
248
+ "lstrip": false,
249
+ "normalized": false,
250
+ "rstrip": false,
251
+ "single_word": false,
252
+ "special": false
253
+ },
254
+ "31": {
255
+ "content": "_",
256
+ "lstrip": false,
257
+ "normalized": false,
258
+ "rstrip": false,
259
+ "single_word": false,
260
+ "special": false
261
+ },
262
+ "32": {
263
+ "content": "`",
264
+ "lstrip": false,
265
+ "normalized": false,
266
+ "rstrip": false,
267
+ "single_word": false,
268
+ "special": false
269
+ },
270
+ "33": {
271
+ "content": "{",
272
+ "lstrip": false,
273
+ "normalized": false,
274
+ "rstrip": false,
275
+ "single_word": false,
276
+ "special": false
277
+ },
278
+ "34": {
279
+ "content": "|",
280
+ "lstrip": false,
281
+ "normalized": false,
282
+ "rstrip": false,
283
+ "single_word": false,
284
+ "special": false
285
+ },
286
+ "35": {
287
+ "content": "}",
288
+ "lstrip": false,
289
+ "normalized": false,
290
+ "rstrip": false,
291
+ "single_word": false,
292
+ "special": false
293
+ },
294
+ "36": {
295
+ "content": "~",
296
+ "lstrip": false,
297
+ "normalized": false,
298
+ "rstrip": false,
299
+ "single_word": false,
300
+ "special": false
301
+ }
302
+ },
303
+ "bos_token": "<cls>",
304
+ "clean_up_tokenization_spaces": true,
305
+ "cls_token": "<cls>",
306
+ "eos_token": "<sep>",
307
+ "extra_special_tokens": {},
308
+ "legacy": true,
309
+ "mask_token": "<mask>",
310
+ "model_max_length": 512,
311
+ "pad_token": "<pad>",
312
+ "sep_token": "<sep>",
313
+ "sp_model_kwargs": {},
314
+ "spaces_between_special_tokens": false,
315
+ "tokenizer_class": "LlamaTokenizer",
316
+ "unk_token": "<unk>",
317
+ "use_default_system_prompt": false
318
+ }
ud.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy
2
+ from transformers import TokenClassificationPipeline
3
+
4
+ class UniversalDependenciesPipeline(TokenClassificationPipeline):
5
+ def _forward(self,model_inputs):
6
+ import torch
7
+ v=model_inputs["input_ids"][0].tolist()
8
+ with torch.no_grad():
9
+ e=self.model(input_ids=torch.tensor([v[0:i]+[self.tokenizer.mask_token_id]+v[i+1:]+[j] for i,j in enumerate(v[1:-1],1)],device=self.device))
10
+ return {"logits":e.logits[:,1:-2,:],**model_inputs}
11
+ def check_model_type(self,supported_models):
12
+ pass
13
+ def postprocess(self,model_outputs,**kwargs):
14
+ if "logits" not in model_outputs:
15
+ return "".join(self.postprocess(x,**kwargs) for x in model_outputs)
16
+ e=model_outputs["logits"].numpy()
17
+ r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
18
+ e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,-numpy.inf)
19
+ g=self.model.config.label2id["X|_|goeswith"]
20
+ r=numpy.tri(e.shape[0])
21
+ for i in range(e.shape[0]):
22
+ for j in range(i+2,e.shape[1]):
23
+ r[i,j]=r[i,j-1] if numpy.argmax(e[i,j-1])==g else 1
24
+ e[:,:,g]+=numpy.where(r==0,0,-numpy.inf)
25
+ m,p=numpy.max(e,axis=2),numpy.argmax(e,axis=2)
26
+ h=self.chu_liu_edmonds(m)
27
+ z=[i for i,j in enumerate(h) if i==j]
28
+ if len(z)>1:
29
+ k,h=z[numpy.argmax(m[z,z])],numpy.min(m)-numpy.max(m)
30
+ 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])]
31
+ h=self.chu_liu_edmonds(m)
32
+ v=[(s,e) for s,e in model_outputs["offset_mapping"][0].tolist() if s<e]
33
+ q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
34
+ if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
35
+ for i,j in reversed(list(enumerate(q[1:],1))):
36
+ if j[-1]=="goeswith" and set([t[-1] for t in q[h[i]+1:i+1]])=={"goeswith"}:
37
+ h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
38
+ v[i-1]=(v[i-1][0],v.pop(i)[1])
39
+ q.pop(i)
40
+ elif v[i-1][1]>v[i][0]:
41
+ h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
42
+ v[i-1]=(v[i-1][0],v.pop(i)[1])
43
+ q.pop(i)
44
+ t=model_outputs["sentence"].replace("\n"," ")
45
+ for i,(s,e) in reversed(list(enumerate(v))):
46
+ w=t[s:e]
47
+ if w.startswith(" "):
48
+ j=len(w)-len(w.lstrip())
49
+ w=w.lstrip()
50
+ v[i]=(v[i][0]+j,v[i][1])
51
+ if w.endswith(" "):
52
+ j=len(w)-len(w.rstrip())
53
+ w=w.rstrip()
54
+ v[i]=(v[i][0],v[i][1]-j)
55
+ if w.strip()=="":
56
+ h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
57
+ v.pop(i)
58
+ q.pop(i)
59
+ u="# text = "+t+"\n"
60
+ for i,(s,e) in enumerate(v):
61
+ u+="\t".join([str(i+1),t[s:e],"_",q[i][0],"_","|".join(q[i][1:-1]),str(0 if h[i]==i else h[i]+1),q[i][-1],"_","_" if i+1<len(v) and e<v[i+1][0] else "SpaceAfter=No"])+"\n"
62
+ return u+"\n"
63
+ def chu_liu_edmonds(self,matrix):
64
+ h=numpy.argmax(matrix,axis=0)
65
+ x=[-1 if i==j else j for i,j in enumerate(h)]
66
+ 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]]:
67
+ y=[]
68
+ while x!=y:
69
+ y=list(x)
70
+ for i,j in enumerate(x):
71
+ x[i]=b(x,i,j)
72
+ if max(x)<0:
73
+ return h
74
+ y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
75
+ z=matrix-numpy.max(matrix,axis=0)
76
+ 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])]])
77
+ 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))]
78
+ h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
79
+ i=y[numpy.argmax(z[x[k[-1]],y] if k[-1]<len(x) else z[y,y])]
80
+ h[i]=x[k[-1]] if k[-1]<len(x) else i
81
+ return h