KoichiYasuoka
commited on
Commit
•
3d0cddb
1
Parent(s):
24769be
bug fix
Browse files
ud.py
CHANGED
@@ -25,17 +25,17 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
25 |
k,h=z[numpy.nanargmax(m[z,z])],numpy.nanmin(m)-numpy.nanmax(m)
|
26 |
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])]
|
27 |
h=self.chu_liu_edmonds(m)
|
28 |
-
|
|
|
29 |
q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
|
30 |
g="aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none"
|
31 |
if g:
|
32 |
for i,j in reversed(list(enumerate(q[1:],1))):
|
33 |
-
if j[-1]=="goeswith" and set([
|
34 |
h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
|
35 |
s,e,c=v.pop(i)
|
36 |
v[i-1]=(v[i-1][0],e,v[i-1][2]+c)
|
37 |
q.pop(i)
|
38 |
-
t=model_outputs["sentence"].replace("\n"," ")
|
39 |
u="\n"
|
40 |
z={"a":"ァ","i":"ィ","u":"ゥ","e":"ェ","o":"ォ","k":"ㇰ","s":"ㇱ","t":"ㇳ","n":"ㇴ","h":"ㇷ","m":"ㇺ","r":"ㇽ","p":"ㇷ゚"}
|
41 |
f=-1
|
@@ -49,7 +49,7 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
49 |
f=-1
|
50 |
if i+1<len(v) and e>v[i+1][0]:
|
51 |
w[-1]=z[c[-1]] if c[-1] in z else "ッ"
|
52 |
-
l=("".join(w) if max(w)<"z" else c).replace("sh","s").replace("ch","c").replace("au","aw").replace("iu","iw").replace("eu","ew").replace("ou","ow").replace("ai","ay").replace("ui","uy").replace("ei","ey").replace("oi","oy") if g else "_"
|
53 |
u=x+"\t".join([str(i+1),"".join(w),l,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"+u
|
54 |
return "# text = "+t+"\n"+u
|
55 |
def chu_liu_edmonds(self,matrix):
|
|
|
25 |
k,h=z[numpy.nanargmax(m[z,z])],numpy.nanmin(m)-numpy.nanmax(m)
|
26 |
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])]
|
27 |
h=self.chu_liu_edmonds(m)
|
28 |
+
t=model_outputs["sentence"].replace("\n"," ")
|
29 |
+
v=[(s,e,c if c!=self.tokenizer.unk_token else t[s:e]) for (s,e),c in zip(model_outputs["offset_mapping"][0].tolist(),self.tokenizer.convert_ids_to_tokens(model_outputs["input_ids"][0].tolist())) if s<e]
|
30 |
q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
|
31 |
g="aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none"
|
32 |
if g:
|
33 |
for i,j in reversed(list(enumerate(q[1:],1))):
|
34 |
+
if j[-1]=="goeswith" and set([k[-1] for k in q[h[i]+1:i+1]])=={"goeswith"}:
|
35 |
h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
|
36 |
s,e,c=v.pop(i)
|
37 |
v[i-1]=(v[i-1][0],e,v[i-1][2]+c)
|
38 |
q.pop(i)
|
|
|
39 |
u="\n"
|
40 |
z={"a":"ァ","i":"ィ","u":"ゥ","e":"ェ","o":"ォ","k":"ㇰ","s":"ㇱ","t":"ㇳ","n":"ㇴ","h":"ㇷ","m":"ㇺ","r":"ㇽ","p":"ㇷ゚"}
|
41 |
f=-1
|
|
|
49 |
f=-1
|
50 |
if i+1<len(v) and e>v[i+1][0]:
|
51 |
w[-1]=z[c[-1]] if c[-1] in z else "ッ"
|
52 |
+
l=("".join(w).replace(" ","") if max(w)<"z" else c).replace("sh","s").replace("ch","c").replace("au","aw").replace("iu","iw").replace("eu","ew").replace("ou","ow").replace("ai","ay").replace("ui","uy").replace("ei","ey").replace("oi","oy") if g else "_"
|
53 |
u=x+"\t".join([str(i+1),"".join(w),l,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"+u
|
54 |
return "# text = "+t+"\n"+u
|
55 |
def chu_liu_edmonds(self,matrix):
|