tlatkowski/multihead-siamese-nets

Predict is not working

datistiquo opened this issue · 5 comments

Hey,

Thanks for this nice repo . I reqrote the vectorizer with keras tokenizer.

I suppose the predict method is not working since of 1.

vectorizer = DatasetVectorizer(model_dir)

which requires of course another argument of sentence_pairs.

and 2. due to


model_name = '{}_{}'.format(model,
                                main_config['PARAMS']['embedding_size'])

model_name is something like cnn_64 but in the model_type.py you just have a dict with



MODELS = {
    ModelType.cnn.name: CnnSiameseNet,
    ModelType.rnn.name: LSTMBasedSiameseNet,
    ModelType.multihead.name: MultiheadAttentionSiameseNet
}

where cnn_64 is not c contained and gives a key error.

Any help?

Hi @datistiquo ,
thanks for pointing this bug out,
I made a quick fix, so please pull the latest version of the repo and try to test the pipeline once again. Currently, i'm working on more convenient way of using models in prediction mode. I will release it soon.

BR

Thanks! I look into it.
Also predict is not working because of batch helper and datasetvectorizer because all of them are built for training? Eg in BatchHelper you have labels etc..So I am struggling right now now to transform all those functions for prediction.

Also in:

  feed_dict = {model.x1: sentence1_batch,
            model.x2: sentence2_batch}
            prediction = session.run([model.temp_sim], feed_dict=feed_dict)

I get the message that you need to feed the tensor is_training like for training.
What is this tensor? where does this come from. up to now I did not find this tensor besides in its definition...

I wonder because for prediction you also need the batch structure like for training, right? So why should this work under while True?

Your change is
model = MODELS[model]

But the model_type.py still ha no key like cnn_64?

@tlatkowski

In the last commit i changed model_name to model in getting the right model reference ( in your example it will be 'cnn' not 'cnn_64' so it should work well after the fix. The second thing regarding predict function: it is only implemented for simple model testing in prediction mode. While loop allows you to provide sentence1 and sentence2 more than once but only for simple testing. So in this case there is no need for having the same batch structure as during training. I use only the vocab created during the training.

Thanks. If I just feed a single x1 and x 2 in feed dict, an error arises because I would need the structure (batchsize, examples) for x1,x2. Better would be to add examples in a loop until having batch size?
What is doing the Variable is_training ?