KoichiYasuoka
commited on
Commit
•
63d7cfa
1
Parent(s):
9fade74
LEMMA support
Browse files
ud.py
CHANGED
@@ -27,7 +27,8 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
27 |
h=self.chu_liu_edmonds(m)
|
28 |
v=[(s,e) for s,e in model_output["offset_mapping"][0].tolist() if s<e]
|
29 |
q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
|
30 |
-
|
|
|
31 |
for i,j in reversed(list(enumerate(q[1:],1))):
|
32 |
if j[-1]=="goeswith" and set([t[-1] for t in q[h[i]+1:i+1]])=={"goeswith"}:
|
33 |
h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
|
@@ -36,7 +37,7 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
36 |
t=model_output["sentence"].replace("\n"," ")
|
37 |
u="# text = "+t+"\n"
|
38 |
for i,(s,e) in enumerate(v):
|
39 |
-
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"
|
40 |
return u+"\n"
|
41 |
def chu_liu_edmonds(self,matrix):
|
42 |
import numpy
|
|
|
27 |
h=self.chu_liu_edmonds(m)
|
28 |
v=[(s,e) for s,e in model_output["offset_mapping"][0].tolist() if s<e]
|
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([t[-1] for t in q[h[i]+1:i+1]])=={"goeswith"}:
|
34 |
h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
|
|
|
37 |
t=model_output["sentence"].replace("\n"," ")
|
38 |
u="# text = "+t+"\n"
|
39 |
for i,(s,e) in enumerate(v):
|
40 |
+
u+="\t".join([str(i+1),t[s:e],t[s:e] if g else "_",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"
|
41 |
return u+"\n"
|
42 |
def chu_liu_edmonds(self,matrix):
|
43 |
import numpy
|