KoichiYasuoka commited on
Commit
7c2f5c4
1 Parent(s): 7cc383a
Files changed (1) hide show
  1. ud.py +10 -13
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=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)]
@@ -51,14 +51,11 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
51
  x[i]=b(x,i,j)
52
  if max(x)<0:
53
  return h
54
- y=[i for i,j in enumerate(x) if j==max(x)]
55
- m=numpy.full((matrix.shape[0]+1,matrix.shape[1]+1),numpy.nan)
56
- m[0:-1,0:-1]=z=matrix-numpy.nanmax(matrix,axis=0)
57
- m[0:-1,-1],m[-1,0:-1],m[-1,-1]=numpy.nanmax(z[:,y],axis=1),numpy.nanmax(z[y,:],axis=0),numpy.nanmax(z[y,y])
58
- m[y,:]=m[:,y]=numpy.nan
59
- m[y,y]=0
60
- k=self.chu_liu_edmonds(m)
61
- j=y[numpy.nanargmax(z[k[-1],y] if k[-1]<z.shape[0] else z[y,y])]
62
- i=k[-1] if k[-1]<z.shape[0] else j
63
- z[0:i,j]=z[i+1:,j]=numpy.nan
64
- return self.chu_liu_edmonds(z)
 
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,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
  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)]
 
51
  x[i]=b(x,i,j)
52
  if max(x)<0:
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[x[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