Skip to content

Fix: honour instance-level Wapiti params in train() and add -modelPath CLI arg#1383

Merged
lfoppiano merged 3 commits into
grobidOrg:masterfrom
cboulanger:fix/abstract-trainer-wapiti-params
Mar 6, 2026
Merged

Fix: honour instance-level Wapiti params in train() and add -modelPath CLI arg#1383
lfoppiano merged 3 commits into
grobidOrg:masterfrom
cboulanger:fix/abstract-trainer-wapiti-params

Conversation

@cboulanger

Copy link
Copy Markdown
Contributor

Summary

Fixes cboulanger#2AbstractTrainer.train() (mode 0) previously ignored any Wapiti parameters set via setParams() and always read them from GrobidProperties. This PR completes the fix in two parts:

1. Fix AbstractTrainer.train() to honour instance-level Wapiti parameter overrides

splitTrainEvaluate() (mode 2) and nFoldEvaluate() (mode 3) already used instance fields as overrides. Mode 0 now does the same:

trainer.setEpsilon(epsilon != 0.0 ? epsilon : GrobidProperties.getEpsilon(model));
trainer.setWindow(window != 0 ? window : GrobidProperties.getWindow(model));
trainer.setNbMaxIterations(nbMaxIterations != 0 ? nbMaxIterations : GrobidProperties.getNbMaxIterations(model));

Fully backwards-compatible: when setParams() has not been called, the instance fields default to 0/0.0 and config values are used as before.

2. Expose Wapiti parameters and custom model output path via TrainerRunner CLI

TrainerRunner (the JAR entry point) never called setParams(), so the fix above was unreachable from the command line. New optional flags:

Flag Type Description
-epsilon double Wapiti convergence threshold
-w int Wapiti window size
-maxIter int Wapiti max iterations
-modelPath path Write trained model directly to this path instead of the default location

When -modelPath is provided:

  • The model is written directly to the specified path (no .new/.old atomic rename).
  • An error is raised if the specified path equals the hardcoded default model path.
  • All other behaviour (no -modelPath) is unchanged.

Use case

Enables callers constructing a trainer programmatically or via CLI/HTTP to supply runtime Wapiti parameters and write versioned/test model files without modifying grobid.yaml.

Affected files

  • grobid-trainer/src/main/java/org/grobid/trainer/AbstractTrainer.java
  • grobid-trainer/src/main/java/org/grobid/trainer/TrainerRunner.java

🤖 Generated with Claude Code

cboulanger and others added 3 commits March 5, 2026 08:21
…ter overrides

train() (mode 0) was always reading epsilon, window and nbMaxIterations
from GrobidProperties, silently ignoring any values set via setParams().
Modes 2 and 3 already used the instance fields as overrides; mode 0 now
follows the same pattern, falling back to the config value when the
instance field is at its default zero.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@lfoppiano lfoppiano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cboulanger

@lfoppiano lfoppiano merged commit 2ea47d7 into grobidOrg:master Mar 6, 2026
2 checks passed
@cboulanger cboulanger deleted the fix/abstract-trainer-wapiti-params branch March 6, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbstractTrainer.train() ignores instance-level Wapiti parameters set via setParams()

2 participants