Evaluator

evaluator

class seq2seq.evaluator.evaluator.Evaluator(loss=<seq2seq.loss.loss.NLLLoss object>, batch_size=64)

Class to evaluate models with given datasets.

Parameters:
  • loss (seq2seq.loss, optional) – loss for evaluator (default: seq2seq.loss.NLLLoss)
  • batch_size (int, optional) – batch size for evaluator (default: 64)
evaluate(model, data)

Evaluate a model on given dataset and return performance.

Parameters:
  • model (seq2seq.models) – model to evaluate
  • data (seq2seq.dataset.dataset.Dataset) – dataset to evaluate against
Returns:

loss of the given model on the given dataset

Return type:

loss (float)

predictor

class seq2seq.evaluator.predictor.Predictor(model, src_vocab, tgt_vocab)
get_decoder_features(src_seq)
predict(src_seq)

Make prediction given src_seq as input.

Parameters:src_seq (list) – list of tokens in source language
Returns:list of tokens in target language as predicted by the pre-trained model
Return type:tgt_seq (list)
predict_n(src_seq, n=1)

Make ‘n’ predictions given src_seq as input.

Parameters:
  • src_seq (list) – list of tokens in source language
  • n (int) – number of predicted seqs to return. If None, it will return just one seq.
Returns:

list of tokens in target language as predicted

by the pre-trained model

Return type:

tgt_seq (list)