KoichiYasuoka
commited on
Commit
•
8c2b6b7
1
Parent(s):
c4adaee
aggregation_strategy="simple"
Browse files
ud.py
CHANGED
@@ -23,10 +23,16 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
23 |
if [0 for i in h if i==0]!=[0]:
|
24 |
m[:,0]+=numpy.where(m[:,0]<numpy.nanmax(m[:,0]),numpy.nan,0)
|
25 |
h=ufal.chu_liu_edmonds.chu_liu_edmonds(m)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
t=model_output["sentence"]
|
27 |
u="# text = "+t+"\n"
|
28 |
-
v=[(s,e) for s,e in model_output["offset_mapping"][0].tolist() if s<e]
|
29 |
for i,(s,e) in enumerate(v,1):
|
30 |
-
|
31 |
-
u+="\t".join([str(i),t[s:e],"_",q[0],"_","|".join(q[1:-1]),str(h[i]),q[-1],"_","_" if i<len(v) and e<v[i][0] else "SpaceAfter=No"])+"\n"
|
32 |
return u+"\n"
|
|
|
23 |
if [0 for i in h if i==0]!=[0]:
|
24 |
m[:,0]+=numpy.where(m[:,0]<numpy.nanmax(m[:,0]),numpy.nan,0)
|
25 |
h=ufal.chu_liu_edmonds.chu_liu_edmonds(m)[0]
|
26 |
+
v=[(s,e) for s,e in model_output["offset_mapping"][0].tolist() if s<e]
|
27 |
+
q=[self.model.config.id2label[p[i,j]].split("|") for i,j in enumerate(h)]
|
28 |
+
if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]=="simple":
|
29 |
+
for i,j in reversed(list(enumerate(q[2:],2))):
|
30 |
+
if j[-1]=="goeswith":
|
31 |
+
h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
|
32 |
+
v[i-2]=(v[i-2][0],v.pop(i-1)[1])
|
33 |
+
q.pop(i)
|
34 |
t=model_output["sentence"]
|
35 |
u="# text = "+t+"\n"
|
|
|
36 |
for i,(s,e) in enumerate(v,1):
|
37 |
+
u+="\t".join([str(i),t[s:e],"_",q[i][0],"_","|".join(q[i][1:-1]),str(h[i]),q[i][-1],"_","_" if i<len(v) and e<v[i][0] else "SpaceAfter=No"])+"\n"
|
|
|
38 |
return u+"\n"
|