MatchZoo-py icon indicating copy to clipboard operation
MatchZoo-py copied to clipboard

Is there any tutorial for using the pretrained model for predicting new sentence pair?

Open anbo724 opened this issue 4 years ago • 1 comments

I have trained the Esim and Bert model. However, I can not found any code for predicting new sentence pair? Is anyone can help?

anbo724 avatar Dec 23 '20 08:12 anbo724

Here's one:

import torch
import matchzoo as mz

from anmm_train import *

test_pack = mz.datasets.wiki_qa.load_data('test', task=ranking_task)
test_processed = preprocessor.transform(test_pack, verbose=0)
testset = mz.dataloader.Dataset(
    data_pack=test_processed,
    mode='point',
    batch_size=32
)
testloader = mz.dataloader.DataLoader(
    dataset=testset,
    device=device,
    stage='test',
    callback=padding_callback
)

if __name__ == "__main__":

    trainer.restore_model("./save/model.pt")
    prediction = trainer.predict(testloader)

    pass

# end main

, where anmm_train is the code copied from repo's README, except Trainer.run(). Though you're in predict stage, the train/test dataset is still required as Trainer takes them as required parameter to construct.

cuter44 avatar Jul 31 '21 09:07 cuter44