Hi Markus,
By looking at source code of Name Finder, I think you can do:
1. implement your own TokenNameFinderFactory which extends OpenNLP's
TokenNameFinderFactory
public class MyTokenNameFinderFactory extends TokenNameFinderFactory
2. in MyTokenNameFinderFactory, override createContextGenerator() to create and
return your custom feature generator.
> AdaptiveFeatureGenerator myFeatureGenerator = new CachedFeatureGenerator(
> new AdaptiveFeatureGenerator[] { new WindowFeatureGenerator(new
> TokenFeatureGenerator(true), 2, 2),
> new WindowFeatureGenerator(new TokenClassFeatureGenerator(true), 2, 2),
> new WindowFeatureGenerator(new CharacterNgramFeatureGenerator(2, 5), 2, 2),
> new WindowFeatureGenerator(new TokenPatternFeatureGenerator(), 2, 2),
> new OutcomePriorFeatureGenerator(), new PreviousMapFeatureGenerator(),
> new BigramNameFeatureGenerator(), new SentenceFeatureGenerator(true, true)
> });
3. Finally, in NameFinderME.train(), instead of new TokenNameFinderFactory(),
use
TokenNameFinderFactory.create("packageName.MyTokenNameFinderFactory", null,
null, new BioCodec())
to inform the class name of your TokenNameFinderFactory.
regards,
Koji
On 2017/10/02 18:58, Markus Kreuzthaler wrote:
Hello!
How can I pass a custom AdaptiveFeatureGenerator to NameFinderME.train ?
TrainingParameters mlParams = new TrainingParameters();
mlParams.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(1000));
mlParams.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(1));
AdaptiveFeatureGenerator myFeatureGenerator = new CachedFeatureGenerator(
new AdaptiveFeatureGenerator[] { new WindowFeatureGenerator(new
TokenFeatureGenerator(true), 2, 2),
new WindowFeatureGenerator(new TokenClassFeatureGenerator(true), 2, 2),
new WindowFeatureGenerator(new CharacterNgramFeatureGenerator(2, 5), 2, 2),
new WindowFeatureGenerator(new TokenPatternFeatureGenerator(), 2, 2),
new OutcomePriorFeatureGenerator(), new PreviousMapFeatureGenerator(),
new BigramNameFeatureGenerator(), new SentenceFeatureGenerator(true, true)
});
TokenNameFinderModel model;
try {
model = NameFinderME.train("de", "entity", sampleStream, mlParams, new
TokenNameFinderFactory());
} finally {
sampleStream.close();
}
I did not see a possibility to pass the object myFeatureGenerator into the
method NameFinderME.train or set it via TokenNameFinderFactory.
Is there somewhere an example how this can be done programmatically?
Thank you!
lg Markus