KoichiYasuoka commited on
Commit
e7fbbfd
1 Parent(s): fdeb6f4

lemma support

Browse files
Files changed (1) hide show
  1. ud.py +4 -2
ud.py CHANGED
@@ -27,7 +27,8 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
27
  h=self.chu_liu_edmonds(m)
28
  v=[(s,e,c) for (s,e),c in zip(model_outputs["offset_mapping"][0].tolist(),self.tokenizer.convert_ids_to_tokens(model_outputs["input_ids"][0].tolist())) if s<e]
29
  q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
30
- if "aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none":
 
31
  for i,j in reversed(list(enumerate(q[1:],1))):
32
  if j[-1]=="goeswith" and set([t[-1] for t in q[h[i]+1:i+1]])=={"goeswith"}:
33
  h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
@@ -48,7 +49,8 @@ class UniversalDependenciesPipeline(TokenClassificationPipeline):
48
  f=-1
49
  if i+1<len(v) and e>v[i+1][0]:
50
  w[-1]=z[c[-1]] if c[-1] in z else "ッ"
51
- u=x+"\t".join([str(i+1),"".join(w),"_",q[i][0],"|".join(q[i][1:-1]),"_",str(0 if h[i]==i else h[i]+1),q[i][-1],"_","_" if i+1<len(v) and e<v[i+1][0] else "SpaceAfter=No"])+"\n"+u
 
52
  return "# text = "+t+"\n"+u
53
  def chu_liu_edmonds(self,matrix):
54
  import numpy
 
27
  h=self.chu_liu_edmonds(m)
28
  v=[(s,e,c) for (s,e),c in zip(model_outputs["offset_mapping"][0].tolist(),self.tokenizer.convert_ids_to_tokens(model_outputs["input_ids"][0].tolist())) if s<e]
29
  q=[self.model.config.id2label[p[j,i]].split("|") for i,j in enumerate(h)]
30
+ g="aggregation_strategy" in kwargs and kwargs["aggregation_strategy"]!="none"
31
+ if g:
32
  for i,j in reversed(list(enumerate(q[1:],1))):
33
  if j[-1]=="goeswith" and set([t[-1] for t in q[h[i]+1:i+1]])=={"goeswith"}:
34
  h=[b if i>b else b-1 for a,b in enumerate(h) if i!=a]
 
49
  f=-1
50
  if i+1<len(v) and e>v[i+1][0]:
51
  w[-1]=z[c[-1]] if c[-1] in z else "ッ"
52
+ l=("".join(w) if max(w)<"z" else c).replace("sh","s").replace("ch","c").replace("au","aw").replace("iu","iw").replace("eu","ew").replace("ou","ow").replace("ai","ay").replace("ui","uy").replace("ei","ey").replace("oi","oy") if g else "_"
53
+ u=x+"\t".join([str(i+1),"".join(w),l,q[i][0],"|".join(q[i][1:-1]),"_",str(0 if h[i]==i else h[i]+1),q[i][-1],"_","_" if i+1<len(v) and e<v[i+1][0] else "SpaceAfter=No"])+"\n"+u
54
  return "# text = "+t+"\n"+u
55
  def chu_liu_edmonds(self,matrix):
56
  import numpy