How to build my own model using OpenNMT-py?

For now, OpenNMT looks to me like sort of an off-the-shelf command-line based tool for machine translation, however, I didn’t find a concrete tutorial for using it as a library to support more flexible further development, i.e., I don’t know how exactly should I use it as a high-level framework (for example, just like allennlp) to build my own model and my own training procedure. To be specific, what should I do if I want to implement my own decoder? Do I just define a new decoder inherits from onmt.decoders.DecoderBase , and then pass it to onmt.models.model.NMTModel ? Also, what should I do if I want to add my own metrics for evaluation and do early stop based on the new metrics? Where should I find the answer to those questions? Any suggestions would be greatly appreciated!

Hi,

To build your own decoder, you indeed can build a class that inherits from onmt.decoders.DecoderBase, like onmt.decoders.transformer.TransformerDecoder for instance.

As for building a model with it, you can declare your new decoder type here which is called in onmt.model_builder.build_decoder.

For early stopping criteria, you may refer to this PR. (If you just want to log another metric, you may have a look at onmt.utils.statistics.

2 Likes