Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference #4

Closed
loretoparisi opened this issue May 25, 2021 · 9 comments
Closed

Inference #4

loretoparisi opened this issue May 25, 2021 · 9 comments

Comments

@loretoparisi
Copy link

loretoparisi commented May 25, 2021

Hello, thanks for this project. I was able to correctly train a structshot using the train script. Could you show how to correctly run the inference for an input sequence?
In my understanding, the loading would look like

import os
import torch

from fewnerd.util.word_encoder import BERTWordEncoder
from fewnerd.model.proto import Proto
from fewnerd.model.nnshot import NNShot

# cache dir
cache_dir = os.getenv("cache_dir", "../../models")
model_path = 'structshot-inter-5-5-seed0.pth.tar'
model_name = 'structshot'
pretrain_ckpt = 'bert-base-uncased'
max_length = 100

# BERT word encoder
word_encoder = BERTWordEncoder(
        pretrain_ckpt,
        max_length)

if model_name == 'proto':
    # use dot instead of L2 distance for proto
    model = Proto(word_encoder, dot=True)
elif model_name == 'nnshot':
    model = NNShot(word_encoder, dot=False)
elif model_name == 'structshot':
    model = NNShot(word_encoder, dot=False)

model.load_state_dict(torch.load(os.path.join(cache_dir, model_path)))

but I get some errors on the state dicts (RuntimeError: Error(s) in loading state_dict for NNShot:) in this way...

Thank you in advance!

@yulinchen99
Copy link
Collaborator

to load the model properly, you can refer to

for name, param in state_dict.items():

@pratikchhapolika
Copy link

@loretoparisi are you able to do inferencing on the trained model?

@loretoparisi
Copy link
Author

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

@pratikchhapolika
Copy link

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

Ok. Thanks. Could you please attach your notebook code and data please. @loretoparisi

@pratikchhapolika
Copy link

@cyl628 For a single input sequence, how should we write the inference script?

@loretoparisi
Copy link
Author

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

Ok. Thanks. Could you please attach your notebook code and data please. @loretoparisi

I have something here I will add the inference code there!

@pratikchhapolika
Copy link

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

Ok. Thanks. Could you please attach your notebook code and data please. @loretoparisi

I have something here I will add the inference code there!

Please add the inference code and how the output looks like for singe input.

@pratikchhapolika
Copy link

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

Ok. Thanks. Could you please attach your notebook code and data please. @loretoparisi

I have something here I will add the inference code there!

@loretoparisi Have you uploaded the inference script?

@loretoparisi
Copy link
Author

@loretoparisi are you able to do inferencing on the trained model?

thanks for the question, it was time ago, but I think so with some trick, I have to check the notebook for the code...

Ok. Thanks. Could you please attach your notebook code and data please. @loretoparisi

I have something here I will add the inference code there!

@loretoparisi Have you uploaded the inference script?

not at this time, I will put it in the repo check updates, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants