Plug-in loader

Contents

Plug-in loader#

mbrs-decode and mbrs-score load plug-in modules via the --plugin_dir option.

Examples#

This tutorial explains how to load a user defined modules.

See also

How to define a new metric

Detailed documentation of the metric customization.

How to define a new decoder

Detailed documentation of the decoder customization.

  1. Define a new metric, decoder, or selector with @register decorator.

    from mbrs.metrics import register, Metric, MetricBLEU
    
    
    @register("my_bleu")
    class MetricMyBLEU(MetricBLEU):
        ...
    
  2. Prepare __init__.py to specify classes to be loaded.

    from .new import MetricNew
    
  3. Then, load the modules with --plugin_dir option with a path to the directory containing the above __init__.py.

    mbrs-decode \
      --plugin_dir path/to/plugins/ \
      hypotheses.txt \
      --num_candidates 1024 \
      --decoder mbr \
      --metric my_bleu
    

    mbrs-score also supports plug-in loading.

    mbrs-score \
      --plugin_dir path/to/plugins/ \
      hypotheses.txt \
      -r references.txt \
      --metric my_bleu