neulab / xnmt

eXtensible Neural Machine Translation
Other
185 stars 44 forks source link

How to load an existing trained model and make predictions on the unseen data? #575

Open emadpres opened 5 years ago

emadpres commented 5 years ago

Hi everyone,

I'm very fresh in AI field and I'm trying to learn how to use XNMT to create a simple English->German translator. Here's my very basic question:

What I did

I followed the Getting Started page and after reading different YAML files, and modified the 01_standard.yaml file to train a model in the following way:

!Experiment
  name: codecomment
  model: !DefaultTranslator
    src_reader: !PlainTextReader
      vocab: !Vocab {vocab_file: /Users/emadpres/Downloads/toy-ende/src-test.vocab.txt}
    trg_reader: !PlainTextReader
      vocab: !Vocab {vocab_file: /Users/emadpres/Downloads/toy-ende/tgt-test.vocab.txt}
  train: !SimpleTrainingRegimen
    run_for_epochs: 2
    src_file: /Users/emadpres/Downloads/toy-ende/src-test.txt
    trg_file: /Users/emadpres/Downloads/toy-ende/tgt-test.txt
    dev_tasks:
      - !LossEvalTask
        src_file: /Users/emadpres/Downloads/toy-ende/src-test.txt
        ref_file: /Users/emadpres/Downloads/toy-ende/tgt-test.txt
  evaluate:
    - !AccuracyEvalTask
      eval_metrics: bleu
      src_file: /Users/emadpres/Downloads/toy-ende/src-test.txt
      ref_file: /Users/emadpres/Downloads/toy-ende/tgt-test.txt
      hyp_file: examples/output/{EXP}.test_hyp

where src-test.txt and tgt-test.txt are a list of sentences (separated with new line) in English and German, respectively. the corresponding "*.vocab.txt" files include the tokens using nltk.tokenize.

It worked and it created the following model files:

Problem

How can I load and use my trained model to make predictions on the unseen data, like giving an English sentence and see what is the result?

I looked into API and sample config files. They usually show how to load and fine-tune an existing model, not how to use it in practice. Note that I don't want to provide a pair of (input, expected output) as we do for the evaluation step. I want to see get the output for a given input.

Any help or hint is welcome.

philip30 commented 5 years ago

Hi, you'd probably want to see this: https://github.com/neulab/xnmt/blob/master/examples/08_load_eval_beam.yaml

This is the way of loading pretrained model and doing evaluation.