KoichiYasuoka
commited on
Commit
•
ee10b29
1
Parent(s):
62ffe79
use numpy.nan
Browse files
ud.py
CHANGED
@@ -22,8 +22,8 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
22 |
h=self.chu_liu_edmonds(m)
|
23 |
z=[i for i,j in enumerate(h) if i==j]
|
24 |
if len(z)>1:
|
25 |
-
k
|
26 |
-
m[:,z]+=[[0 if j in z and (i!=j or i==k) else
|
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)]
|
@@ -53,9 +53,9 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
|
|
53 |
return h
|
54 |
y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
|
55 |
z=matrix-numpy.nanmax(matrix,axis=0)
|
56 |
-
m=numpy.block([[z[x,:][:,x],numpy.
|
57 |
-
k=[j if i==len(x) else x[j] if j<len(x) else y[numpy.
|
58 |
h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
|
59 |
-
i=y[numpy.
|
60 |
h[i]=x[k[-1]] if k[-1]<len(x) else i
|
61 |
return h
|
|
|
22 |
h=self.chu_liu_edmonds(m)
|
23 |
z=[i for i,j in enumerate(h) if i==j]
|
24 |
if len(z)>1:
|
25 |
+
k=z[numpy.nanargmax(m[z,z])]
|
26 |
+
m[:,z]+=[[0 if j in z and (i!=j or i==k) else numpy.nan for i in z] for j in range(m.shape[0])]
|
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)]
|
|
|
53 |
return h
|
54 |
y,x=[i for i,j in enumerate(x) if j==max(x)],[i for i,j in enumerate(x) if j<max(x)]
|
55 |
z=matrix-numpy.nanmax(matrix,axis=0)
|
56 |
+
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])]])
|
57 |
+
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))]
|
58 |
h=[j if i in y else k[x.index(i)] for i,j in enumerate(h)]
|
59 |
+
i=y[numpy.nanargmax(z[k[-1],y] if k[-1]<len(x) else z[y,y])]
|
60 |
h[i]=x[k[-1]] if k[-1]<len(x) else i
|
61 |
return h
|