KoichiYasuoka commited on
Commit
a77d761
1 Parent(s): 56054ea

improve goeswith

Browse files
Files changed (2) hide show
  1. README.md +6 -0
  2. ud.py +6 -0
README.md CHANGED
@@ -36,6 +36,12 @@ class UDgoeswith(object):
36
  e=self.model(input_ids=torch.tensor(x)).logits.numpy()[:,1:-2,:]
37
  r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
38
  e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
 
 
 
 
 
 
39
  m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
40
  m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
41
  p=numpy.zeros(m.shape)
 
36
  e=self.model(input_ids=torch.tensor(x)).logits.numpy()[:,1:-2,:]
37
  r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
38
  e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
39
+ g=self.model.config.label2id["X|_|goeswith"]
40
+ r=numpy.tri(e.shape[0])
41
+ for i in range(e.shape[0]):
42
+ for j in range(i+2,e.shape[1]):
43
+ r[i,j]=r[i,j-1] if numpy.nanargmax(e[i,j-1])==g else 1
44
+ e[:,:,g]+=numpy.where(r==0,0,numpy.nan)
45
  m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
46
  m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
47
  p=numpy.zeros(m.shape)
ud.py CHANGED
@@ -13,6 +13,12 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
13
  e=model_output["logits"].numpy()
14
  r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
15
  e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
 
 
 
 
 
 
16
  m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
17
  m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
18
  p=numpy.zeros(m.shape)
 
13
  e=model_output["logits"].numpy()
14
  r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
15
  e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
16
+ g=self.model.config.label2id["X|_|goeswith"]
17
+ r=numpy.tri(e.shape[0])
18
+ for i in range(e.shape[0]):
19
+ for j in range(i+2,e.shape[1]):
20
+ r[i,j]=r[i,j-1] if numpy.nanargmax(e[i,j-1])==g else 1
21
+ e[:,:,g]+=numpy.where(r==0,0,numpy.nan)
22
  m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
23
  m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
24
  p=numpy.zeros(m.shape)