davanstrien HF Staff commited on
Commit
1fcc105
·
1 Parent(s): d612804

nuextract3: add --instructions for chat_template_kwargs.instructions

Browse files

Exposes NuExtract3's `instructions` chat-template kwarg, a free-text
steering lever for output formats and routing across union/optional
schema branches. Mirrors the existing `--enable-thinking` passthrough:
new arg, plumbed via main() into chat_template_kwargs only when truthy
(no-op when omitted).

Docs: https://huggingface.co/numind/NuExtract3#instructions

Smoke (davanstrien/ufo-ColPali, 3 samples, extraction mode,
template={"title": "string", "author": "string"},
instruction="Prepend 'INSTR-OK::' to the title value"):
sentinel landed in 3/3 extractions.

Teklia French vital-records (58 cards, superset Baptême/Mariage/Décès
template + type_acte enum + French routing instruction): strict
F1 0.281 -> 0.321. Modest; the model partially honours the
branch-null routing (emits empty {} subdicts rather than null for
non-matched branches), which is consistent with NuExtract3's
shape-binding template engine. Per-user instruction tuning lives
downstream of this flag.

Files changed (1) hide show
  1. nuextract3.py +18 -0
nuextract3.py CHANGED
@@ -27,6 +27,10 @@ Modes are selected via flags:
27
  - --template SOURCE -> structured extraction with a NuExtract template
28
  - --schema SOURCE -> structured extraction with a JSON Schema
29
  (auto-converted via numind.nuextract_utils)
 
 
 
 
30
 
31
  --template / --schema each accept inline JSON, a URL, or a local file path, so a
32
  schema can be hosted (e.g. on an HF dataset's raw URL) and reused across jobs:
@@ -277,6 +281,7 @@ def main(
277
  template_arg: Optional[str] = None,
278
  schema_arg: Optional[str] = None,
279
  enable_thinking: bool = False,
 
280
  temperature: Optional[float] = None,
281
  model: str = MODEL_DEFAULT,
282
  hf_token: str = None,
@@ -351,6 +356,8 @@ def main(
351
  chat_template_kwargs["template"] = json.dumps(template, indent=4)
352
  else:
353
  chat_template_kwargs["mode"] = mode
 
 
354
 
355
  logger.info(f"Processing {len(dataset)} images in batches of {batch_size}")
356
  logger.info(f"Output will be written to column: {output_column}")
@@ -646,6 +653,16 @@ Examples:
646
  action="store_true",
647
  help="Enable reasoning mode (slower, better on hard documents)",
648
  )
 
 
 
 
 
 
 
 
 
 
649
  parser.add_argument(
650
  "--temperature",
651
  type=float,
@@ -712,6 +729,7 @@ Examples:
712
  template_arg=args.template,
713
  schema_arg=args.schema,
714
  enable_thinking=args.enable_thinking,
 
715
  temperature=args.temperature,
716
  model=args.model,
717
  hf_token=args.hf_token,
 
27
  - --template SOURCE -> structured extraction with a NuExtract template
28
  - --schema SOURCE -> structured extraction with a JSON Schema
29
  (auto-converted via numind.nuextract_utils)
30
+ - --instructions STR -> free-text guidance passed through to the model
31
+ (output-format rules, branch routing, etc.).
32
+ Combines with any of the modes above.
33
+ See https://huggingface.co/numind/NuExtract3#instructions
34
 
35
  --template / --schema each accept inline JSON, a URL, or a local file path, so a
36
  schema can be hosted (e.g. on an HF dataset's raw URL) and reused across jobs:
 
281
  template_arg: Optional[str] = None,
282
  schema_arg: Optional[str] = None,
283
  enable_thinking: bool = False,
284
+ instructions: Optional[str] = None,
285
  temperature: Optional[float] = None,
286
  model: str = MODEL_DEFAULT,
287
  hf_token: str = None,
 
356
  chat_template_kwargs["template"] = json.dumps(template, indent=4)
357
  else:
358
  chat_template_kwargs["mode"] = mode
359
+ if instructions:
360
+ chat_template_kwargs["instructions"] = instructions
361
 
362
  logger.info(f"Processing {len(dataset)} images in batches of {batch_size}")
363
  logger.info(f"Output will be written to column: {output_column}")
 
653
  action="store_true",
654
  help="Enable reasoning mode (slower, better on hard documents)",
655
  )
656
+ parser.add_argument(
657
+ "--instructions",
658
+ default=None,
659
+ help=(
660
+ "Free-text instructions passed to NuExtract via "
661
+ "chat_template_kwargs.instructions (e.g. routing guidance across "
662
+ "optional schema branches, output-format rules). "
663
+ "See https://huggingface.co/numind/NuExtract3#instructions"
664
+ ),
665
+ )
666
  parser.add_argument(
667
  "--temperature",
668
  type=float,
 
729
  template_arg=args.template,
730
  schema_arg=args.schema,
731
  enable_thinking=args.enable_thinking,
732
+ instructions=args.instructions,
733
  temperature=args.temperature,
734
  model=args.model,
735
  hf_token=args.hf_token,