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

How to load finetuned NER model in allenlp? #110

Open
tomasonjo opened this issue Nov 16, 2020 · 3 comments
Open

How to load finetuned NER model in allenlp? #110

tomasonjo opened this issue Nov 16, 2020 · 3 comments

Comments

@tomasonjo
Copy link

I have trained the NER model on sciie dataset using the following config:

DATASET='sciie'
TASK='ner'
with_finetuning='_finetune' #'_finetune'  # or '' for not fine tuning
dataset_size=38124

export BERT_VOCAB=/home/tomaz/neo4j/scibert/model/vocab.txt
export BERT_WEIGHTS=/home/tomaz/neo4j/scibert/model/weights.tar.gz

This worked nicely and I got a model.tar.gz as an output. Now when I try to load it in AllenNLP lib:

from allennlp.predictors.predictor import Predictor
predictor = Predictor.from_path("model.tar.gz")

I get the following error:

ConfigurationError: bert-pretrained not in acceptable choices for dataset_reader.token_indexers.bert.type: ['single_id', 'characters', 'elmo_characters', 'spacy', 'pretrained_transformer', 'pretrained_transformer_mismatched']. You should either use the --include-package flag to make sure the correct module is loaded, or use a fully qualified class name in your config file like {"model": "my_module.models.MyModel"} to have it imported automatically.

Any idea how to fix this?

@tomasonjo
Copy link
Author

I have made a lot of progress, currently I use:

from allennlp.predictors.predictor import Predictor
from scibert.models.bert_crf_tagger import *
from scibert.models.bert_text_classifier import *
from scibert.models.dummy_seq2seq import *
from scibert.dataset_readers.classification_dataset_reader import *

predictor = Predictor.from_path("scibert_ner/model.tar.gz")
dataset_reader="classification_dataset_reader")
predictor.predict(
  sentence="Did Uriah honestly think he could beat The Legend of Zelda in under three hours?"
)

and I get the following error:

No default predictor for model type bert_crf_tagger.\nPlease specify a predictor explicitly

There is an option to add a predictor_name parameter to load module from path, but I don't know what to pick that would work

@PetterBerntsson
Copy link

I'm also having trouble running the model (#107), but I could at least load my model in a hacky way.

Please keep me updated if you get it running!

@gshashi
Copy link

gshashi commented Mar 24, 2021

If someone still encounter this issue, I could be able to solve it by including predictor_name while loading model. something like this.

predictor = Predictor.from_path("scibert_ner/model.tar.gz",predictor_name="sentence-tagger")

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