← Back to Pull requests

Add --per-item-disable: change the disabled lexemes (-L) between inputs #2

Open
olzama opened this pull request with 54 lines diff across 2 files
View on GitHub
olzama olzama commented on Nov 24, 2026 18:09 UTC
Author

Add --per-item-disable: change the disabled lexemes (-L) between inputs

A new, opt-in command-line option for parsing mode. With --per-item-disable:

  • an input line #DISABLE <lexemes> sets the lexemes disabled for the inputs that follow it, in the same format and with the same substring matching as -L;

  • a bare #DISABLE line restores the -L value given on the command line;

  • a directive is #DISABLE followed by the end of the line or whitespace (#DISABLED ... is an ordinary input);

  • such lines are not parsed; each is answered on stdout by one line, NOTE: #DISABLE: ..., followed by two empty lines, the terminator of every item, so a client that reads one response per input line (pydelphin's ACEParser.interact, console or --tsdb-stdout) stays in step;

  • parsing mode only: with -e or a transfer grammar ACE refuses the option.
  • Without the option nothing changes. The change is confined to main.c (the option, one branch in the input loop next to the LUI : commands, and the parsing-mode check) plus one line in doc/options.wiki.

    Motivation

    -L can only be set once, when ACE starts. A caller that wants a different restriction for every sentence (for example, parsing with only the lexical entries a supertagger proposes for that sentence) has to start ACE once per sentence. Starting ACE and touching the mapped grammar image costs about 30 to 35 ms per sentence with the ERG on our machine, more than the parsing itself for most short sentences. With this option one ACE process serves all sentences.

    Usage

    $ ace -g erg.dat -1 --per-item-disable
    #DISABLE bark_v1
    NOTE: #DISABLE: 1 lexeme name(s) disabled for the following inputs
    
    The dog barked.          <- parsed without bark_v1
    ...
    #DISABLE
    NOTE: #DISABLE: restored the -L setting for the following inputs
    
    The dog barked.          <- parsed with the command-line -L (here: none)
    ...
    

    Testing

    Tested with ERG 2025 (compiled with this branch's base, main at 31afda8) and 300 sentences drawn at random (fixed seed) from the Redwoods dev profiles:

    1. Two builds from the same commit. main as is ("stock") and main with this patch ("patched"), same compiler and flags; both report the same version.
    2. Without the option, nothing changes. Both builds parse the 300 sentences in one process each, first-best (-1) and 20-best (-n 20), with the same memory limits. We compare the console output item by item: the MRS and the derivation of every result, in rank order (timings excluded).
    3. With the option, the same parses as restarting ACE. For each sentence we take a restriction list as a real caller would build it: our supertagger's five best lexical types per word (probability at least 0.001) turned into lexical entries, and every other lexeme that could match the sentence's words disabled, about 70 lexemes per sentence on average. Then:
    - reference: stock main started once per sentence with -L <that list>;
    - patched: one process started with --per-item-disable, fed #DISABLE <that list> followed by the sentence, for all 300 sentences in turn.
    We check that every directive is answered by exactly one NOTE: #DISABLE: block in its place, drop those blocks, and compare item by item as in step 2, for -1 and for -n 20.
    4. The restriction really changes between inputs. In one process: "The dog barked." with #DISABLE bark_v1, then a bare #DISABLE, then #DISABLE bark_v1 again. Without bark_v1 ACE gives only fragment analyses without the verb's predicate; with it, the ordinary parse. Each of the three outputs equals a separate stock run with the corresponding -L.
    5. Review fixes. #DISABLED bark_v1 is parsed as a sentence, with the same output as stock; #DISABLE<TAB>bark_v1<TAB> gives the same output as #DISABLE bark_v1; -e --per-item-disable exits with an error. pydelphin 1.11's ACEParser.interact (console and --tsdb-stdout), sent #DISABLE lines and sentences in turn, gets one response per line and the expected parses (pydelphin's own option check had to be told about the new flag for this test).
    6. Timing. Wall-clock time per sentence for step 3's two set-ups, on the same machine in the same session (it was running other jobs, so the absolute numbers are higher than on an idle machine).

    | Check | Result |
    |---|---|
    | Step 2, -1 and -n 20 | byte-identical |
    | Step 3, -1 | 300 of 300 identical, one acknowledgement per directive |
    | Step 3, -n 20 | 300 of 300 identical, one acknowledgement per directive |
    | Steps 4 and 5 | pass |
    | Step 6, time per sentence, one ACE run per sentence → one process | 178 → 138 ms (-n 20: 183 → 141 ms) |

    Time limits: ACE's --timeout is wall-clock time (alarm()). The first run of steps 2 and 3 used --timeout=60 on a heavily loaded machine, and a few sentences then differed between runs (in step 2's 20-best run and in two items of step 3); rerun without --timeout, all of them are identical. The table reports those reruns for the affected comparisons.

    The first revision of this change (without the review fixes), applied to the 0.9.34 release, passed the same checks (and a full run over all 2,062 dev sentences with identical results), and is used by our parser and its public demo. The test script is available on request.

    License

    Contributed under ACE's existing license.

    Diff: 54 lines (+53 / -1) across 2 files Reviewer: arademaker Review duration: 14694m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.28) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.28 · 54 lines diff across 2 files
    0.28
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.87 · 5 substantive comment(s)
    0.87
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    88%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.240
    Real PR Conversation Timeline
    7 items
    arademaker arademaker commented on code on Nov 24, 2026 19:44 UTC
    Code Review
    main.c:1
    @@ -437,7 +457,12 @@ struct job_stats	main_input_loop(FILE	*fin)
     			}
     			if(fin==stdin)stdin_time += timer();
     			//start_timer(tid);
    -			if(lui_mode && lineptr[0]==':')
    +			if(per_item_disable && !strncmp(lineptr, "#DISABLE", 8))

    No response for #DISABLE lines. Nothing is written to stdout or stderr when a directive is consumed. A client that sends one line and then blocks reading one response (e.g. pydelphin's ACE interface, or art with --tsdb-stdout) will hang — and those are the most likely users of a per-item setting. Could we print a short acknowledgement (at least in tsdb-stdout mode), or otherwise clearly document that clients must not wait for a reply?

    arademaker arademaker commented on code on Nov 24, 2026 19:44 UTC
    Code Review
    main.c:1
    @@ -437,7 +457,12 @@ struct job_stats	main_input_loop(FILE	*fin)
     			}
     			if(fin==stdin)stdin_time += timer();
     			//start_timer(tid);
    -			if(lui_mode && lineptr[0]==':')
    +			if(per_item_disable && !strncmp(lineptr, "#DISABLE", 8))

    Prefix check has no word boundary. strncmp(lineptr, "#DISABLE", 8) also matches e.g. #DISABLED items follow: that line is silently not parsed, and D items follow becomes the disabled list for all following sentences. Suggest also requiring lineptr[8] to be '\0' or whitespace (' ', '\t', '\r', '\n').

    arademaker arademaker commented on code on Nov 24, 2026 19:44 UTC
    Code Review
    main.c:1
    @@ -437,7 +457,12 @@ struct job_stats	main_input_loop(FILE	*fin)
     			}
     			if(fin==stdin)stdin_time += timer();
     			//start_timer(tid);
    -			if(lui_mode && lineptr[0]==':')
    +			if(per_item_disable && !strncmp(lineptr, "#DISABLE", 8))

    Minor: this is only checked in the parsing branch of main_input_loop. With --per-item-disable in generation/transfer mode, a #DISABLE line goes to read_mrs_string_or_line and is treated as malformed MRS. Maybe reject the option outside parsing mode, or skip these lines in the generation branch too.

    arademaker arademaker commented on code on Nov 24, 2026 19:44 UTC
    Code Review
    main.c:1
    @@ -37,6 +37,25 @@ char	*save_grammar_path = 0;
     char	*load_grammar_path = 0;
     char	*sentence_path = 0, *master_addr = 0;
     int	question = 0, exhaustive = 1, lui_mode = 0, inhibit_pack = 0, best_only = 0;
    +
    +// --per-item-disable: in parsing mode, an input line "#DISABLE <lexemes>" sets the list of
    +// disabled lexemes (same format and matching as -L) for the items that follow it;
    +// a bare "#DISABLE" line restores the -L value given on the command line.
    +// Such lines are not parsed and produce no output.  Without the option, nothing changes.
    +int	per_item_disable = 0;
    +static char	*per_item_disable_value = 0, *per_item_disable_cmdline = 0;
    +static int	per_item_disable_seen = 0;
    +static void	set_per_item_disable(char	*arg)
    +{
    +	extern char	*disable_signs;
    +	if(!per_item_disable_seen) { per_item_disable_cmdline = disable_signs; per_item_disable_seen = 1; }
    +	while(*arg==' ' || *arg=='\t')arg++;
    +	int	n = strlen(arg);
    +	while(n > 0 && (arg[n-1]=='\n' || arg[n-1]=='\r' || arg[n-1]==' '))arg[--n] = 0;
    +	if(per_item_disable_value) { free(per_item_disable_value); per_item_disable_value = 0; }
    +	if(n > 0) { per_item_disable_value = strdup(arg); disable_signs = per_item_disable_value; }

    Nit: the trailing trim strips \n, \r and space but not \t, unlike the leading trim above, so #DISABLE foo\t stores foo\t. Harmless with the current strstr matching, but worth making consistent.

    arademaker arademaker commented on Nov 24, 2026 19:44 UTC
    Reviewer

    Thanks for this — being able to change the disabled lexemes per item without restarting ACE is useful. A few comments inline.

    One more point that can't be attached inline because the line isn't in the diff: disabled lexemes are matched in morpho.c (lex_handler, ~line 225) with strstr(disable_signs, lex->word). That tests whether the lexeme name occurs anywhere in the list string, so #DISABLE hotdog_n1 would also disable dog_n1 or hot if such lexemes exist. This predates the PR (-L has always behaved this way), but the PR documents it as "same format and matching as -L" and now lets every input item trigger it. Splitting the list into whole names and comparing exactly would be safer — fine as a follow-up.

    olzama olzama commented on Nov 30, 2026 16:16 UTC
    Author

    Thank you for the review! I've pushed a second commit that addresses the inline comments.

    Reviewers
    Assignees
    olzama olzama
    Labels
    risk: low confidence: 88.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 28.4% (LOW) · Higher = larger blast radius
    28.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 88.1% · Lower = rushed or shallow review
    88.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.4% · Safe to merge
    3.4%
    Repository