File size: 11,842 Bytes
8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 7bd4e87 8abcc73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
#! /bin/sh
# pip3 install 'transformers>=4.10.0' seqeval datasets supar==1.1.3
test -f run_ner.py || curl -LO https://raw.githubusercontent.com/huggingface/transformers/v`pip3 list | sed -n 's/^transformers *\([^ ]*\) *$/\1/p'`/examples/pytorch/token-classification/run_ner.py
python3 -c '
from suparkanbun.simplify import simplify
c=[]
h=[0]
while True:
try:
s=input()
except:
quit()
t=s.strip().split("\t")
if len(t)==10:
if t[0]!="#":
t[0]=str(len(c)+1)
i=len(t[1])
if i>1:
form=t[1]
lemma=t[2]
head=t[6]
deprel=t[7]
for j in range(0,i-1):
t[1]=form[j]
if t[1] in simplify:
t[1]=simplify[t[1]]
t[2]=lemma[j]
t[6]="-1"
t[7]="compound"
c.append(list(t))
t[0]=str(len(c)+1)
t[1]=form[i-1]
t[2]=lemma[i-1]
t[6]=head
t[7]=deprel
if t[1] in simplify:
t[1]=simplify[t[1]]
c.append(list(t))
h.append(len(c))
elif s.strip()=="":
for t in c:
t[6]=str(int(t[0])+1 if t[6]=="-1" else h[int(t[6])])
print("\t".join(t))
print("")
c=[]
h=[0]
' < lzh_kyoto.conllu | tee simplified.conllu | python3 -c '
tokens=[]
tags=[]
while True:
try:
s=input()
except:
if len(tokens)>0:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
quit()
t=s.split("\t")
if len(t)==10:
p=t[4]+","+t[3]+","+t[5]
for c in t[1]:
tokens.append(c)
tags.append(p)
elif len(tokens)>80:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
tokens=[]
tags=[]
' | tee simplifiedPOS.json | nawk '
{
if(NR%10>0)
printf("%s\n",$0)>"trainPOS.json";
else
printf("%s\n",$0)>"validPOS.json";
}'
sed 's/^.*"tags":\[//' trainPOS.json | tr '"' '\012' | sort -u | egrep '^[nvps],' > labelPOS.txt
if [ ! -f guwenbert-base.pos/pytorch_model.bin ]
then mkdir -p guwenbert-base.pos
python3 run_ner.py --model_name_or_path ethanyt/guwenbert-base --train_file trainPOS.json --validation_file validPOS.json --output_dir guwenbert-base.pos --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f guwenbert-large.pos/pytorch_model.bin ]
then mkdir -p guwenbert-large.pos
python3 run_ner.py --model_name_or_path ethanyt/guwenbert-large --train_file trainPOS.json --validation_file validPOS.json --output_dir guwenbert-large.pos --do_train --do_eval --overwrite_output_dir --per_device_train_batch_size=4 --per_device_eval_batch_size=4
fi
nawk '
BEGIN{
f[0]="test.conllu";
f[1]="dev.conllu";
for(i=2;i<10;i++)
f[i]="train.conllu";
}
{
printf("%s\n",$0)>f[i%10];
if($0=="")
i++;
}' simplified.conllu
if [ ! -f guwenbert-base.pos/guwenbert-base.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p guwenbert-base.pos/guwenbert-base.supar -c biaffine-dep-en -f bert --bert ethanyt/guwenbert-base --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
if [ ! -f guwenbert-large.pos/guwenbert-large.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p guwenbert-large.pos/guwenbert-large.supar -c biaffine-dep-en -f bert --bert ethanyt/guwenbert-large --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
python3 -c '
tokens=[]
tags=[]
i=0
while True:
try:
s=input()
except:
if len(tokens)>0:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
quit()
t=s.split("\t")
if len(t)==10:
for c in t[1]:
tokens.append(c)
i+=1
else:
if i==1:
tags.append("S")
elif i==2:
tags+=["B","E"]
elif i==3:
tags+=["B","E2","E"]
else:
tags+=["B"]+["M"]*(i-4)+["E3","E2","E"]
i=0
if len(tokens)>80:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
tokens=[]
tags=[]
' < simplified.conllu | tee simplifiedDanku.json | nawk '
{
if(NR%10>0)
printf("%s\n",$0)>"trainDanku.json";
else
printf("%s\n",$0)>"validDanku.json";
}'
sed 's/^.*"tags":\[//' trainDanku.json | tr '"' '\012' | sort -u | egrep '^[A-Z]' > labelDanku.txt
if [ ! -f guwenbert-base.danku/pytorch_model.bin ]
then mkdir -p guwenbert-base.danku
python3 run_ner.py --model_name_or_path ethanyt/guwenbert-base --train_file trainDanku.json --validation_file validDanku.json --output_dir guwenbert-base.danku --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f guwenbert-large.danku/pytorch_model.bin ]
then mkdir -p guwenbert-large.danku
python3 run_ner.py --model_name_or_path ethanyt/guwenbert-large --train_file trainDanku.json --validation_file validDanku.json --output_dir guwenbert-large.danku --do_train --do_eval --overwrite_output_dir --per_device_train_batch_size=4 --per_device_eval_batch_size=4
fi
python3 -c '
c=[]
h=[0]
while True:
try:
s=input()
except:
quit()
t=s.strip().split("\t")
if len(t)==10:
if t[0]!="#":
t[0]=str(len(c)+1)
i=len(t[1])
if i>1:
form=t[1]
lemma=t[2]
head=t[6]
deprel=t[7]
for j in range(0,i-1):
t[1]=form[j]
t[2]=lemma[j]
t[6]="-1"
t[7]="compound"
c.append(list(t))
t[0]=str(len(c)+1)
t[1]=form[i-1]
t[2]=lemma[i-1]
t[6]=head
t[7]=deprel
c.append(list(t))
h.append(len(c))
elif s.strip()=="":
for t in c:
t[6]=str(int(t[0])+1 if t[6]=="-1" else h[int(t[6])])
print("\t".join(t))
print("")
c=[]
h=[0]
' < lzh_kyoto.conllu | tee traditional.conllu | python3 -c '
tokens=[]
tags=[]
while True:
try:
s=input()
except:
if len(tokens)>0:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
quit()
t=s.split("\t")
if len(t)==10:
p=t[4]+","+t[3]+","+t[5]
for c in t[1]:
tokens.append(c)
tags.append(p)
elif len(tokens)>80:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
tokens=[]
tags=[]
' | tee traditionalPOS.json | nawk '
{
if(NR%10>0)
printf("%s\n",$0)>>"trainPOS.json";
else
printf("%s\n",$0)>>"validPOS.json";
}'
if [ ! -f roberta-classical-chinese-base-char.pos/pytorch_model.bin ]
then mkdir -p roberta-classical-chinese-base-char.pos
python3 run_ner.py --model_name_or_path KoichiYasuoka/roberta-classical-chinese-base-char --train_file trainPOS.json --validation_file validPOS.json --output_dir roberta-classical-chinese-base-char.pos --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f roberta-classical-chinese-large-char.pos/pytorch_model.bin ]
then mkdir -p roberta-classical-chinese-large-char.pos
python3 run_ner.py --model_name_or_path KoichiYasuoka/roberta-classical-chinese-large-char --train_file trainPOS.json --validation_file validPOS.json --output_dir roberta-classical-chinese-large-char.pos --do_train --do_eval --overwrite_output_dir --per_device_train_batch_size=4 --per_device_eval_batch_size=4
fi
nawk '
BEGIN{
f[0]="test.conllu";
f[1]="dev.conllu";
for(i=2;i<10;i++)
f[i]="train.conllu";
}
{
printf("%s\n",$0)>>f[i%10];
if($0=="")
i++;
}' traditional.conllu
if [ ! -f roberta-classical-chinese-base-char.pos/roberta-classical-chinese-base-char.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p roberta-classical-chinese-base-char.pos/roberta-classical-chinese-base-char.supar -c biaffine-dep-en -f bert --bert KoichiYasuoka/roberta-classical-chinese-base-char --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
if [ ! -f roberta-classical-chinese-large-char.pos/roberta-classical-chinese-large-char.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p roberta-classical-chinese-large-char.pos/roberta-classical-chinese-large-char.supar -c biaffine-dep-en -f bert --bert KoichiYasuoka/roberta-classical-chinese-large-char --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
python3 -c '
tokens=[]
tags=[]
i=0
while True:
try:
s=input()
except:
if len(tokens)>0:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
quit()
t=s.split("\t")
if len(t)==10:
for c in t[1]:
tokens.append(c)
i+=1
else:
if i==1:
tags.append("S")
elif i==2:
tags+=["B","E"]
elif i==3:
tags+=["B","E2","E"]
else:
tags+=["B"]+["M"]*(i-4)+["E3","E2","E"]
i=0
if len(tokens)>80:
print("{\"tokens\":[\""+"\",\"".join(tokens)+"\"],\"tags\":[\""+"\",\"".join(tags)+"\"]}")
tokens=[]
tags=[]
' < traditional.conllu | tee traditionalDanku.json | nawk '
{
if(NR%10>0)
printf("%s\n",$0)>>"trainDanku.json";
else
printf("%s\n",$0)>>"validDanku.json";
}'
if [ ! -f roberta-classical-chinese-base-char.danku/pytorch_model.bin ]
then mkdir -p roberta-classical-chinese-base-char.danku
python3 run_ner.py --model_name_or_path KoichiYasuoka/roberta-classical-chinese-base-char --train_file trainDanku.json --validation_file validDanku.json --output_dir roberta-classical-chinese-base-char.danku --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f roberta-classical-chinese-large-char.danku/pytorch_model.bin ]
then mkdir -p roberta-classical-chinese-large-char.danku
python3 run_ner.py --model_name_or_path KoichiYasuoka/roberta-classical-chinese-large-char --train_file trainDanku.json --validation_file validDanku.json --output_dir roberta-classical-chinese-large-char.danku --do_train --do_eval --overwrite_output_dir --per_device_train_batch_size=4 --per_device_eval_batch_size=4
fi
nawk '
{
if(NR%10>0)
printf("%s\n",$0)>"trainPOS.json";
else
printf("%s\n",$0)>"validPOS.json";
}' traditionalPOS.json
if [ ! -f sikubert.pos/pytorch_model.bin ]
then mkdir -p sikubert.pos
python3 run_ner.py --model_name_or_path SIKU-BERT/sikubert --train_file trainPOS.json --validation_file validPOS.json --output_dir sikubert.pos --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f sikuroberta.pos/pytorch_model.bin ]
then mkdir -p sikuroberta.pos
python3 run_ner.py --model_name_or_path SIKU-BERT/sikuroberta --train_file trainPOS.json --validation_file validPOS.json --output_dir sikuroberta.pos --do_train --do_eval --overwrite_output_dir
fi
nawk '
BEGIN{
f[0]="test.conllu";
f[1]="dev.conllu";
for(i=2;i<10;i++)
f[i]="train.conllu";
}
{
printf("%s\n",$0)>f[i%10];
if($0=="")
i++;
}' traditional.conllu
if [ ! -f sikubert.pos/sikubert.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p sikubert.pos/sikubert.supar -c biaffine-dep-en -f bert --bert SIKU-BERT/sikubert --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
if [ ! -f sikuroberta.pos/sikuroberta.supar ]
then python3 -m supar.cmds.biaffine_dep train -b -d 0 -p sikuroberta.pos/sikuroberta.supar -c biaffine-dep-en -f bert --bert SIKU-BERT/sikuroberta --train train.conllu --dev dev.conllu --test test.conllu --embed='' --proj
fi
nawk '
{
if(NR%10>0)
printf("%s\n",$0)>"trainDanku.json";
else
printf("%s\n",$0)>"validDanku.json";
}' traditionalDanku.json
if [ ! -f sikubert.danku/pytorch_model.bin ]
then mkdir -p sikubert.danku
python3 run_ner.py --model_name_or_path SIKU-BERT/sikubert --train_file trainDanku.json --validation_file validDanku.json --output_dir sikubert.danku --do_train --do_eval --overwrite_output_dir
fi
if [ ! -f sikuroberta.danku/pytorch_model.bin ]
then mkdir -p sikuroberta.danku
python3 run_ner.py --model_name_or_path SIKU-BERT/sikuroberta --train_file trainDanku.json --validation_file validDanku.json --output_dir sikuroberta.danku --do_train --do_eval --overwrite_output_dir
fi
exit 0
|