code wiki / (root) / nx_absa_lib.nx

nx_absa_lib.nx

buildroot/runtime/nx_absa_lib.nx

35526 B883 linesdepth 3pulls 3 transitivereach 5 importersview sourcekind librarytopic absa
docsdependenciesstructsconstsfunctions

about

nx_absa_lib.nx -- the SCORING MATH for SemEval-2014 Task 4 subtask 1 (aspect term extraction), as a shared lib so the CLI (nx_absa_bench) and the gate (nx_absa_bench_gate) share ONE definition of P, R and F1 and one gold parser. The metric is the paper's own (Pontiki et al. 2014, eq. 1-2): P=|S and G|/|S|, R=|S and G|/|G|, F1=2PR/(P+R), which for a set overlap is exactly 2*inter/(|S|+|G|) -- computed from counts so there is no double rounding. Everything is permil (1000 = 1.00). Nothing here is a threshold: the lib reports numbers, the gate says what a correct scorer must return, and the CLI prints the number beside the published winners. THE GOLD FORMAT (ABSA-PyTorch .seg mirror of the official test set): three lines per record -- line 0 mod 3: the sentence with the aspect term replaced by the placeholder $T$ line 1 mod 3: the aspect term (single or multi word, e.g. "hard disk", "delivery times") line 2 mod 3: the polarity (1 / 0 / -1) The gold aspect-term SET G is the distinct normalised terms across the term lines (footnote 3 of the paper counts occurrences; this is the distinct-term variant, DECLARED, a related but not identical metric). THE PREDICTOR is a UNIGRAM DOCUMENT-FREQUENCY baseline over the test sentences: it composes the ONE tokenizer (rm_next_token via rm_mine_doc) and the ONE frequency ranker (rm_mine_rank) from nx_reviewmine_lib, so no second tokenizer or ranker exists. It is a weak proxy for Hu-Liu (2004) frequent-noun-phrase mining -- our miner does not yet extract multi-word noun phrases (rung rm_aspects), so a multi-word gold term is UNMATCHABLE by a unigram prediction under exact-set match. That is the honest reason this baseline sits far below the supervised systems, and the gap IS the un-landed rung. license_tier: ORIGINAL No hw writes (Rule 26). LIB.

dependencies 2 imports · 5 importers

nx_syscalls.nx nx_reviewmine_lib.nx nx_absa_lib.nx nx_absa_bench.nx nx_absa_bench_gate.nx nx_absa_seq.nx nx_absa_seq_gate.nx nx_absa_seqextract.nx

imports: nx_syscalls.nxnx_reviewmine_lib.nx

imported by: nx_absa_bench.nxnx_absa_bench_gate.nxnx_absa_seq.nxnx_absa_seq_gate.nxnx_absa_seqextract.nx

structs

none

consts

24const AB_PERMIL: i64 = 1000
25const AB_P: i64 = 0
26const AB_R: i64 = 1
27const AB_F1: i64 = 2
28const AB_PRF_N: i64 = 3
30const AB_O_INTER: i64 = 0
31const AB_O_NS: i64 = 1
32const AB_O_NG: i64 = 2
33const AB_O_P: i64 = 3
34const AB_O_R: i64 = 4
35const AB_O_F1: i64 = 5
36const AB_O_K: i64 = 6
37const AB_O_VOCAB: i64 = 7
38const AB_O_N: i64 = 8
40const AB_SET_SLOTS: i64 = 65536 // power of two; a SemEval domain has ~1-2k distinct aspect terms
41const AB_SET_ARENA: i64 = 4194304 // AB_SET_SLOTS * avg term bytes, generous (multi-word terms allowed)
42const AB_TERM_MAX: i64 = 256 // longest aspect term stored
43const AB_RECORD_LINES: i64 = 3 // the .seg record is three lines
44const AB_TERM_LINE: i64 = 1 // lineno mod 3 == 1 is the aspect-term line
45const AB_SENT_LINE: i64 = 0 // lineno mod 3 == 0 is the sentence line
46const AB_MIN_SUPPORT: i64 = 1 // a candidate term must appear in at least one sentence
47const AB_ARENA_TAIL: i64 = 1 // the NUL after a stored term
49const AB_STOPWORDS: *u8 = "knowledge/reviewmine/stopwords.conf"
187const AB_RECON_CAP: i64 = 8192 // a reconstructed review sentence
188const AB_DOLLAR: i64 = 36 // '$'
189const AB_UPPER_T: i64 = 84 // 'T' -- the $T$ placeholder the .seg masks the aspect term with
190const AB_PLACEHOLDER_LEN: i64 = 3 // the three bytes of $T$
294const AB_POL_POS: i64 = 0
295const AB_POL_NEG: i64 = 1
296const AB_POL_NEU: i64 = 2
297const AB_POL_OTHER: i64 = 3
298const AB_POL_N: i64 = 4
299const AB_Q_RECORDS: i64 = 0
300const AB_Q_POS: i64 = 1
301const AB_Q_NEG: i64 = 2
302const AB_Q_NEU: i64 = 3
303const AB_Q_OTHER: i64 = 4
304const AB_Q_MAJ_CLASS: i64 = 5
305const AB_Q_MAJ_ACC: i64 = 6
306const AB_Q_LEX_ACC: i64 = 7
307const AB_Q_LEX_PRED_POS: i64 = 8
308const AB_Q_LEX_PRED_NEG: i64 = 9
309const AB_Q_LEX_PRED_NEU: i64 = 10
310const AB_Q_LEX_TERMS: i64 = 11 // lexicon terms loaded; 0 means the lexicon arm had no cues and says so
311const AB_Q_N: i64 = 12
312const AB_LEX_DIR_DEFAULT: *u8 = "knowledge/reviewmine/"
313const AB_LEX_DEFECT_FILE: *u8 = "lexicon_defect.conf"
314const AB_LEX_NOTMEET_FILE: *u8 = "lexicon_notmeet.conf"
315const AB_LEX_EXCEED_FILE: *u8 = "lexicon_exceed.conf"
316const AB_PATH_CAP: i64 = 512
317const AB_CH_ONE: i64 = 49 // '1'
318const AB_POL_LEN_ONE: i64 = 1 // "1" and "0" are one byte
319const AB_POL_LEN_NEG: i64 = 2 // "-1" is two bytes
444const AB_NG_MINSUP_PERMIL: i64 = 10 // Hu and Liu 2004: a frequent feature appears in at least 1 percent of sentences
445const AB_NG_MINSUP_FLOOR: i64 = 1
446const AB_NG_MIN_PSUPPORT: i64 = 3 // Hu and Liu 2004: a subset phrase with p-support below 3 is redundant
447const AB_NG_JOIN: i64 = 32 // the space between the two words of a stored bigram
448const AB_NG_MAX_TOKENS: i64 = 512 // tokens one record carries into the n-gram pass; more is counted truncated
449const AB_NG_BG_CAP: i64 = 66 // RM_TOK_MAX * 2 + a space + a NUL
450const AB_NG_STOP: i64 = 0 - 1 // a stopword in the token list: a phrase boundary
451const AB_REC_N: i64 = 6 // s0 l0 s1 l1 s2 l2
452const AB_G_INTER: i64 = 0
453const AB_G_NS: i64 = 1
454const AB_G_NG: i64 = 2
455const AB_G_P: i64 = 3
456const AB_G_R: i64 = 4
457const AB_G_F1: i64 = 5
458const AB_G_K: i64 = 6
459const AB_G_CAND: i64 = 7 // candidates after support and pruning
460const AB_G_BIGRAMS: i64 = 8 // frequent bigrams among the candidates
461const AB_G_PRUNED: i64 = 9 // unigrams pruned by p-support
462const AB_G_MINSUP: i64 = 10
463const AB_G_MATCHED_BIGRAMS: i64 = 11
464const AB_G_TRUNC: i64 = 12 // records whose token list overflowed
465const AB_G_RECORDS: i64 = 13
466const AB_G_N: i64 = 14
669const HS_HASH: i64 = 0
670const HS_OFF: i64 = 1
671const HS_LEN: i64 = 2
672const HS_ARENA: i64 = 3
673const HS_USED: i64 = 4
674const HS_CNT: i64 = 5
675const HS_FIELDS: i64 = 6
676const AB_GRAM_CAP: i64 = 512
677const AB_D_INTER: i64 = 0
678const AB_D_NS: i64 = 1
679const AB_D_NG: i64 = 2
680const AB_D_P: i64 = 3
681const AB_D_R: i64 = 4
682const AB_D_F1: i64 = 5
683const AB_D_DICT: i64 = 6
684const AB_D_RECORDS: i64 = 7
685const AB_D_N: i64 = 8

functions

61func ab_norm(src: *u8, n: i64, out: *u8, cap: i64) -> i64
84func ab_set_reset() -> i64
called by 1: ab_gold_load calls 1: sys_mmap
101func ab_set_add_norm(s: *u8, n: i64) -> i64
called by 1: ab_set_add_raw calls 2: rm_hashrm_catn
130func ab_set_add_raw(src: *u8, n: i64) -> i64
called by 1: ab_gold_load calls 2: ab_normab_set_add_norm
136func ab_set_has_raw(src: *u8, n: i64) -> i64
156func ab_set_count() -> i64 { return ab_cnt }
called by 1: ab_gold_load
160func ab_prf(inter: i64, ns: i64, ng: i64, out: *i64) -> i64
169func ab_gold_load(path: *u8) -> i64
195func ab_reconstruct(sent: *u8, sl: i64, term: *u8, tl: i64, out: *u8, cap: i64) -> i64
227func ab_eval(path: *u8, k: i64, out: *i64) -> i64
321func ab_pol_class(p: *u8, n: i64) -> i64
called by 1: ab_polarity
332func ab_pol_name(c: i64) -> *u8
called by 1: main
338func ab_lex_path(dir: *u8, file: *u8, out: *u8) -> i64
called by 1: ab_polarity calls 1: rm_cat
345func ab_lex_cues(text: *u8, n: i64, tok: *u8, ip: *i64, cues: *i64) -> i64
362func ab_polarity(path: *u8, lexdir: *u8, out: *i64) -> i64
479func ab_ng_reset() -> i64
called by 1: ab_ngram_eval calls 1: sys_mmap
498func ab_ng_tokens(text: *u8, n: i64, tok: *u8, ip: *i64, trunc: *i64) -> i64
515func ab_ng_bigram(left: i64, right: i64) -> i64
523func ab_ng_bump(slot: i64, doc: i64) -> i64 { if ab_last[slot] != doc { ab_last[slot] = doc; ab_df[slot] = ab_df[slot] + 1 } return 0 }
called by 1: ab_ngram_eval
524func ab_ng_psbump(slot: i64, doc: i64) -> i64 { if ab_pslast[slot] != doc { ab_pslast[slot] = doc; ab_ps[slot] = ab_ps[slot] + 1 } return 0 }
called by 1: ab_ngram_eval
526func ab_rec_next(b: *u8, n: i64, ip: *i64, r: *i64) -> i64
541func ab_ngram_eval(path: *u8, k: i64, minsup_pin: i64, out: *i64) -> i64
687func hs_new() -> *i64
called by 2: ab_dict_evalsp_eval calls 1: sys_mmap
697func hs_reset(h: *i64) -> i64
705func hs_add_norm(h: *i64, s: *u8, n: i64) -> i64
called by 1: hs_add_raw calls 2: rm_hashrm_catn
737func hs_add_raw(h: *i64, s: *u8, n: i64) -> i64 { let m: i64 = ab_norm(s, n, ab_nbuf, AB_TERM_MAX); return hs_add_norm(h, ab_nbuf, m) }
738func hs_has_raw(h: *i64, s: *u8, n: i64) -> i64
761func hs_count(h: *i64) -> i64 { return h[HS_CNT] }
763func hs_slot_raw(h: *i64, s: *u8, n: i64) -> i64
786func ab_dict_load(path: *u8, h: *i64) -> i64
803func ab_dict_try(dic: *i64, pred: *i64, g: *u8, n: i64) -> i64
called by 1: ab_dict_eval calls 2: hs_has_rawhs_add_raw
807func ab_dict_eval(train: *u8, test: *u8, out: *i64) -> i64