KoichiYasuoka
commited on
Commit
•
4def3a8
1
Parent(s):
b1fd97b
improve goeswith
Browse files
README.md
CHANGED
@@ -37,6 +37,12 @@ class UDgoeswith(object):
|
|
37 |
e=self.model(input_ids=torch.tensor(x)).logits.numpy()[:,1:-2,:]
|
38 |
r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
|
39 |
e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
|
41 |
m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
|
42 |
p=numpy.zeros(m.shape)
|
|
|
37 |
e=self.model(input_ids=torch.tensor(x)).logits.numpy()[:,1:-2,:]
|
38 |
r=[1 if i==0 else -1 if j.endswith("|root") else 0 for i,j in sorted(self.model.config.id2label.items())]
|
39 |
e+=numpy.where(numpy.add.outer(numpy.identity(e.shape[0]),r)==0,0,numpy.nan)
|
40 |
+
g=self.model.config.label2id["X|_|goeswith"]
|
41 |
+
r=numpy.tri(e.shape[0])
|
42 |
+
for i in range(e.shape[0]):
|
43 |
+
for j in range(i+2,e.shape[1]):
|
44 |
+
r[i,j]=r[i,j-1] if numpy.nanargmax(e[i,j-1])==g else 1
|
45 |
+
e[:,:,g]+=numpy.where(r==0,0,numpy.nan)
|
46 |
m=numpy.full((e.shape[0]+1,e.shape[1]+1),numpy.nan)
|
47 |
m[1:,1:]=numpy.nanmax(e,axis=2).transpose()
|
48 |
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)
|