nx_postag_eval.nx source
↩ module page · 43 lines · 2085 B
1// nx_postag_eval.nx -- train the estate's POS tagger (nx_postag) on a CoNLL-U treebank and report token accuracy on a
2// second one. ONE call: nx_postag_eval <train.conllu> <test.conllu> [label]
3// The bar is the published accuracy of feature-based taggers on UD English EWT UPOS (a greedy averaged perceptron
4// with this feature set reads about 93-95 percent in the literature); the receipt carries the sentence and token
5// counts so a partial read cannot pass as a whole one. license_tier: ORIGINAL No hw writes (Rule 26).
6import "nx_syscalls.nx"
7import "nx_reviewmine_lib.nx"
8import "nx_postag.nx"
9
10const PE_ARG_TRAIN: i64 = 1
11const PE_ARG_TEST: i64 = 2
12const PE_ARG_LABEL: i64 = 3
13const PE_EXIT_USAGE: i64 = 2
14const PE_EXIT_NOFILE: i64 = 3
15
16func main(argc: i64, argv: *i64) -> i64 {
17 if argc <= PE_ARG_TEST {
18 rm_w("usage: nx_postag_eval <train.conllu> <test.conllu> [label]\n" as *u8)
19 sys_exit(PE_EXIT_USAGE); return PE_EXIT_USAGE
20 }
21 let train: *u8 = argv[PE_ARG_TRAIN] as *u8
22 let test: *u8 = argv[PE_ARG_TEST] as *u8
23 var label: *u8 = test
24 if argc > PE_ARG_LABEL { label = argv[PE_ARG_LABEL] as *u8 }
25 let out: *i64 = sys_mmap(PT_O_N * RM_I64_BYTES) as *i64
26 if pt_eval(train, test, out) < 0 {
27 rm_w("POSTAG REFUSED cannot read a treebank\n" as *u8)
28 sys_exit(PE_EXIT_NOFILE); return PE_EXIT_NOFILE
29 }
30 rm_w("POSTAG-EVAL corpus=" as *u8); rm_w(label)
31 rm_w(" tokens=" as *u8); rm_wn(out[PT_O_TOKENS])
32 rm_w(" correct=" as *u8); rm_wn(out[PT_O_CORRECT])
33 rm_w(" accuracy_permil=" as *u8); rm_wn(out[PT_O_ACC])
34 rm_w(" train_sentences=" as *u8); rm_wn(out[PT_O_TRAINSENT])
35 rm_w(" train_tokens=" as *u8); rm_wn(out[PT_O_TRAINTOK])
36 rm_w(" test_sentences=" as *u8); rm_wn(out[PT_O_TESTSENT])
37 rm_w(" epochs=" as *u8); rm_wn(PT_EPOCHS)
38 rm_w(" last_epoch_updates=" as *u8); rm_wn(out[PT_O_UPDATES])
39 rm_w(" unknown_gold_tags=" as *u8); rm_wn(out[PT_O_UNKTAG])
40 rm_w(" metric=greedy-averaged-perceptron-upos-token-accuracy-on-a-conllu-treebank\n" as *u8)
41 sys_exit(0)
42 return 0
43}